home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / GCC257S3.ZIP / src / gcc-257 / cp-decl2.c < prev    next >
C/C++ Source or Header  |  1993-11-24  |  82KB  |  2,729 lines

  1. /* Process declarations and variables for C compiler.
  2.    Copyright (C) 1988, 1992, 1993 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@cygnus.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* Process declarations and symbol lookup for C front end.
  23.    Also constructs types; the standard scalar types at initialization,
  24.    and structure, union, array and enum types when they are declared.  */
  25.  
  26. /* ??? not all decl nodes are given the most useful possible
  27.    line numbers.  For example, the CONST_DECLs for enum values.  */
  28.  
  29. #include "config.h"
  30. #include <stdio.h>
  31. #include "tree.h"
  32. #include "rtl.h"
  33. #include "flags.h"
  34. #include "cp-tree.h"
  35. #include "cp-decl.h"
  36. #include "cp-lex.h"
  37.  
  38. extern tree grokdeclarator ();
  39. extern tree get_file_function_name ();
  40. static void grok_function_init ();
  41.  
  42. /* A list of virtual function tables we must make sure to write out.  */
  43. tree pending_vtables;
  44.  
  45. /* A list of static class variables.  This is needed, because a
  46.    static class variable can be declared inside the class without
  47.    an initializer, and then initialized, staticly, outside the class.  */
  48. tree pending_statics;
  49.  
  50. extern tree pending_addressable_inlines;
  51.  
  52. /* Used to help generate temporary names which are unique within
  53.    a function.  Reset to 0 by start_function.  */
  54.  
  55. static int temp_name_counter;
  56.  
  57. /* Same, but not reset.  Local temp variables and global temp variables
  58.    can have the same name.  */
  59. static int global_temp_name_counter;
  60.  
  61. /* Flag used when debugging cp-spew.c */
  62.  
  63. extern int spew_debug;
  64.  
  65. /* C (and C++) language-specific option variables.  */
  66.  
  67. /* Nonzero means allow type mismatches in conditional expressions;
  68.    just make their values `void'.   */
  69.  
  70. int flag_cond_mismatch;
  71.  
  72. /* Nonzero means give `double' the same size as `float'.  */
  73.  
  74. int flag_short_double;
  75.  
  76. /* Nonzero means don't recognize the keyword `asm'.  */
  77.  
  78. int flag_no_asm;
  79.  
  80. /* Nonzero means don't recognize the non-ANSI builtin functions.  */
  81.  
  82. int flag_no_builtin;
  83.  
  84. /* Nonzero means do some things the same way PCC does.  */
  85.  
  86. int flag_traditional;
  87.  
  88. /* Nonzero means to treat bitfields as unsigned unless they say `signed'.  */
  89.  
  90. int flag_signed_bitfields = 1;
  91.  
  92. /* Nonzero means handle `#ident' directives.  0 means ignore them.  */
  93.  
  94. int flag_no_ident = 0;
  95.  
  96. /* Nonzero means handle things in ANSI, instead of GNU fashion.  This
  97.    flag should be tested for language behavior that's different between
  98.    ANSI and GNU, but not so horrible as to merit a PEDANTIC label.  */
  99.  
  100. int flag_ansi = 0;
  101.  
  102. /* Nonzero means do argument matching for overloading according to the
  103.    ANSI rules, rather than what g++ used to believe to be correct.  */
  104.  
  105. int flag_ansi_overloading = 0;
  106.  
  107. /* Nonzero means do emit exported implementations of functions even if
  108.    they can be inlined.  */
  109.  
  110. int flag_implement_inlines = 1;
  111.  
  112. /* Nonzero means do emit exported implementations of templates, instead of
  113.    multiple static copies in each file that needs a definition. */
  114.  
  115. int flag_external_templates = 0;
  116.  
  117. /* Nonzero means warn about implicit declarations.  */
  118.  
  119. int warn_implicit = 1;
  120.  
  121. /* Nonzero means warn when all ctors or dtors are private, and the class
  122.    has no friends.  */
  123.  
  124. int warn_ctor_dtor_privacy = 1;
  125.  
  126. /* Like `warn_return_type', but this is set by users, whereas
  127.    `warn_return_type' is set by the compiler.  */
  128.  
  129. int explicit_warn_return_type;
  130.  
  131. /* Nonzero means give string constants the type `const char *'
  132.    to get extra warnings from them.  These warnings will be too numerous
  133.    to be useful, except in thoroughly ANSIfied programs.  */
  134.  
  135. int warn_write_strings;
  136.  
  137. /* Nonzero means warn about pointer casts that can drop a type qualifier
  138.    from the pointer target type.  */
  139.  
  140. int warn_cast_qual;
  141.  
  142. /* Nonzero means warn that dbx info for template class methods isn't fully
  143.    supported yet.  */
  144.  
  145. int warn_template_debugging;
  146.  
  147. /* Warn about traditional constructs whose meanings changed in ANSI C.  */
  148.  
  149. int warn_traditional;
  150.  
  151. /* Nonzero means warn about sizeof(function) or addition/subtraction
  152.    of function pointers.  */
  153.  
  154. int warn_pointer_arith;
  155.  
  156. /* Nonzero means warn for non-prototype function decls
  157.    or non-prototyped defs without previous prototype.  */
  158.  
  159. int warn_strict_prototypes;
  160.  
  161. /* Nonzero means warn for any function def without prototype decl.  */
  162.  
  163. int warn_missing_prototypes;
  164.  
  165. /* Nonzero means warn about multiple (redundant) decls for the same single
  166.    variable or function.  */
  167.  
  168. int warn_redundant_decls;
  169.  
  170. /* Warn if initializer is not completely bracketed.  */
  171.  
  172. int warn_missing_braces;
  173.  
  174. /* Warn about *printf or *scanf format/argument anomalies. */
  175.  
  176. int warn_format;
  177.  
  178. /* Warn about a subscript that has type char.  */
  179.  
  180. int warn_char_subscripts;
  181.  
  182. /* Warn if a type conversion is done that might have confusing results.  */
  183.  
  184. int warn_conversion;
  185.  
  186. /* Warn if adding () is suggested.  */
  187.  
  188. int warn_parentheses = 1;
  189.  
  190. /* Non-zero means warn in function declared in derived class has the
  191.    same name as a virtual in the base class, but fails to match the
  192.    type signature of any virtual function in the base class.  */
  193. int warn_overloaded_virtual;
  194.  
  195. /* Non-zero means warn when converting between different enumeral types.  */
  196. int warn_enum_clash;
  197.  
  198. /* Non-zero means warn when declaring a class that has a non virtual
  199.    destructor, when it really ought to have a virtual one. */
  200. int warn_nonvdtor = 1;
  201.  
  202. /* Nonzero means `$' can be in an identifier.
  203.    See cccp.c for reasons why this breaks some obscure ANSI C programs.  */
  204.  
  205. #ifndef DOLLARS_IN_IDENTIFIERS
  206. #define DOLLARS_IN_IDENTIFIERS 1
  207. #endif
  208. int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
  209.  
  210. /* Nonzero for -no-strict-prototype switch: do not consider empty
  211.    argument prototype to mean function takes no arguments.  */
  212.  
  213. int strict_prototype = 1;
  214. int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
  215.  
  216. /* Nonzero means that labels can be used as first-class objects */
  217.  
  218. int flag_labels_ok;
  219.  
  220. /* Non-zero means to collect statistics which might be expensive
  221.    and to print them when we are done.  */
  222. int flag_detailed_statistics;
  223.  
  224. /* C++ specific flags.  */   
  225. /* Nonzero for -fall-virtual: make every member function (except
  226.    constructors) lay down in the virtual function table.  Calls
  227.    can then either go through the virtual function table or not,
  228.    depending.  */
  229.  
  230. int flag_all_virtual;
  231.  
  232. /* Zero means that `this' is a *const.  This gives nice behavior in the
  233.    2.0 world.  1 gives 1.2-compatible behavior.  2 gives Spring behavior.
  234.    -2 means we're constructing an object and it has fixed type.  */
  235.  
  236. int flag_this_is_variable;
  237.  
  238. /* Nonzero means memoize our member lookups.  */
  239.  
  240. int flag_memoize_lookups; int flag_save_memoized_contexts;
  241.  
  242. /* 3 means write out only virtuals function tables `defined'
  243.    in this implementation file.
  244.    2 means write out only specific virtual function tables
  245.    and give them (C) public visibility.
  246.    1 means write out virtual function tables and give them
  247.    (C) public visibility.
  248.    0 means write out virtual function tables and give them
  249.    (C) static visibility (default).
  250.    -1 means declare virtual function tables extern.  */
  251.  
  252. int write_virtuals;
  253.  
  254. /* Nonzero means we should attempt to elide constructors when possible.  */
  255.  
  256. int flag_elide_constructors;
  257.  
  258. /* Nonzero means recognize and handle exception handling constructs.
  259.    2 means handle exceptions the way Spring wants them handled.  */
  260.  
  261. int flag_handle_exceptions;
  262.  
  263. /* Nonzero means recognize and handle exception handling constructs.
  264.    Use ansi syntax and semantics.  WORK IN PROGRESS!
  265.    2 means handle exceptions the way Spring wants them handled.  */
  266.  
  267. int flag_ansi_exceptions;
  268.  
  269. /* Nonzero means that member functions defined in class scope are
  270.    inline by default.  */
  271.  
  272. int flag_default_inline = 1;
  273.  
  274. /* Controls whether enums and ints freely convert.
  275.    1 means with complete freedom.
  276.    0 means enums can convert to ints, but not vice-versa.  */
  277. int flag_int_enum_equivalence;
  278.  
  279. /* Controls whether compiler is operating under LUCID's Cadillac
  280.    system.  1 means yes, 0 means no.  */
  281. int flag_cadillac;
  282.  
  283. /* Controls whether compiler generates code to build objects
  284.    that can be collected when they become garbage.  */
  285. int flag_gc;
  286.  
  287. /* Controls whether compiler generates 'dossiers' that give
  288.    run-time type information.  */
  289. int flag_dossier;
  290.  
  291. /* Nonzero if we wish to output cross-referencing information
  292.    for the GNU class browser.  */
  293. extern int flag_gnu_xref;
  294.  
  295. /* Nonzero if compiler can make `reasonable' assumptions about
  296.    references and objects.  For example, the compiler must be
  297.    conservative about the following and not assume that `a' is nonnull:
  298.  
  299.    obj &a = g ();
  300.    a.f (2);
  301.  
  302.    In general, it is `reasonable' to assume that for many programs,
  303.    and better code can be generated in that case.  */
  304.  
  305. int flag_assume_nonnull_objects;
  306.  
  307. /* Table of language-dependent -f options.
  308.    STRING is the option name.  VARIABLE is the address of the variable.
  309.    ON_VALUE is the value to store in VARIABLE
  310.     if `-fSTRING' is seen as an option.
  311.    (If `-fno-STRING' is seen as an option, the opposite value is stored.)  */
  312.  
  313. static struct { char *string; int *variable; int on_value;} lang_f_options[] =
  314. {
  315.   {"signed-char", &flag_signed_char, 1},
  316.   {"unsigned-char", &flag_signed_char, 0},
  317.   {"signed-bitfields", &flag_signed_bitfields, 1},
  318.   {"unsigned-bitfields", &flag_signed_bitfields, 0},
  319.   {"short-enums", &flag_short_enums, 1},
  320.   {"short-double", &flag_short_double, 1},
  321.   {"cond-mismatch", &flag_cond_mismatch, 1},
  322.   {"asm", &flag_no_asm, 0},
  323.   {"builtin", &flag_no_builtin, 0},
  324.   {"ident", &flag_no_ident, 0},
  325.   {"labels-ok", &flag_labels_ok, 1},
  326.   {"stats", &flag_detailed_statistics, 1},
  327.   {"this-is-variable", &flag_this_is_variable, 1},
  328.   {"strict-prototype", &strict_prototypes_lang_cplusplus, 1},
  329.   {"all-virtual", &flag_all_virtual, 1},
  330.   {"memoize-lookups", &flag_memoize_lookups, 1},
  331.   {"elide-constructors", &flag_elide_constructors, 1},
  332.   {"handle-exceptions", &flag_handle_exceptions, 1},
  333.   {"ansi-exceptions", &flag_ansi_exceptions, 1},
  334.   {"spring-exceptions", &flag_handle_exceptions, 2},
  335.   {"default-inline", &flag_default_inline, 1},
  336.   {"dollars-in-identifiers", &dollars_in_ident, 1},
  337.   {"enum-int-equiv", &flag_int_enum_equivalence, 1},
  338.   {"gc", &flag_gc, 1},
  339.   {"dossier", &flag_dossier, 1},
  340.   {"xref", &flag_gnu_xref, 1},
  341.   {"nonnull-objects", &flag_assume_nonnull_objects, 1},
  342.   {"implement-inlines", &flag_implement_inlines, 1},
  343.   {"external-templates", &flag_external_templates, 1},
  344.   {"ansi-overloading", &flag_ansi_overloading, 1},
  345. };
  346.  
  347. /* Decode the string P as a language-specific option.
  348.    Return 1 if it is recognized (and handle it);
  349.    return 0 if not recognized.  */
  350.  
  351. int   
  352. lang_decode_option (p)
  353.      char *p;
  354. {
  355.   if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
  356.     flag_traditional = 1, dollars_in_ident = 1, flag_writable_strings = 1,
  357.     flag_this_is_variable = 1;
  358.   /* The +e options are for cfront compatibility.  They come in as
  359.      `-+eN', to kludge around gcc.c's argument handling.  */
  360.   else if (p[0] == '-' && p[1] == '+' && p[2] == 'e')
  361.     {
  362.       int old_write_virtuals = write_virtuals;
  363.       if (p[3] == '1')
  364.     write_virtuals = 1;
  365.       else if (p[3] == '0')
  366.     write_virtuals = -1;
  367.       else if (p[3] == '2')
  368.     write_virtuals = 2;
  369.       else error ("invalid +e option");
  370.       if (old_write_virtuals != 0
  371.       && write_virtuals != old_write_virtuals)
  372.     error ("conflicting +e options given");
  373.     }
  374.   else if (p[0] == '-' && p[1] == 'f')
  375.     {
  376.       /* Some kind of -f option.
  377.      P's value is the option sans `-f'.
  378.      Search for it in the table of options.  */
  379.       int found = 0, j;
  380.  
  381.       p += 2;
  382.       /* Try special -f options.  */
  383.  
  384.       if (!strcmp (p, "save-memoized"))
  385.     {
  386.       flag_memoize_lookups = 1;
  387.       flag_save_memoized_contexts = 1;
  388.       found = 1;
  389.     }
  390.       if (!strcmp (p, "no-save-memoized"))
  391.     {
  392.       flag_memoize_lookups = 0;
  393.       flag_save_memoized_contexts = 0;
  394.       found = 1;
  395.     }
  396.       else if (! strncmp (p, "cadillac", 8))
  397.     {
  398.       flag_cadillac = atoi (p+9);
  399.       found = 1;
  400.     }
  401.       else if (! strncmp (p, "no-cadillac", 11))
  402.     {
  403.       flag_cadillac = 0;
  404.       found = 1;
  405.     }
  406.       else if (! strcmp (p, "gc"))
  407.     {
  408.       flag_gc = 1;
  409.       /* This must come along for the ride.  */
  410.       flag_dossier = 1;
  411.       found = 1;
  412.     }
  413.       else if (! strcmp (p, "no-gc"))
  414.     {
  415.       flag_gc = 0;
  416.       /* This must come along for the ride.  */
  417.       flag_dossier = 0;
  418.       found = 1;
  419.     }
  420.       else for (j = 0;
  421.         !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
  422.         j++)
  423.     {
  424.       if (!strcmp (p, lang_f_options[j].string))
  425.         {
  426.           *lang_f_options[j].variable = lang_f_options[j].on_value;
  427.           /* A goto here would be cleaner,
  428.          but breaks the vax pcc.  */
  429.           found = 1;
  430.         }
  431.       if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
  432.           && ! strcmp (p+3, lang_f_options[j].string))
  433.         {
  434.           *lang_f_options[j].variable = ! lang_f_options[j].on_value;
  435.           found = 1;
  436.         }
  437.     }
  438.       return found;
  439.     }
  440.   else if (p[0] == '-' && p[1] == 'W')
  441.     {
  442.       int setting = 1;
  443.  
  444.       /* The -W options control the warning behavior of the compiler.  */
  445.       p += 2;
  446.  
  447.       if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
  448.     setting = 0, p += 3;
  449.  
  450.       if (!strcmp (p, "implicit"))
  451.     warn_implicit = setting;
  452.       else if (!strcmp (p, "return-type"))
  453.     explicit_warn_return_type = setting;
  454.       else if (!strcmp (p, "ctor-dtor-privacy"))
  455.     warn_ctor_dtor_privacy = setting;
  456.       else if (!strcmp (p, "write-strings"))
  457.     warn_write_strings = setting;
  458.       else if (!strcmp (p, "cast-qual"))
  459.     warn_cast_qual = setting;
  460.       else if (!strcmp (p, "traditional"))
  461.     warn_traditional = setting;
  462.       else if (!strcmp (p, "char-subscripts"))
  463.     warn_char_subscripts = setting;
  464.       else if (!strcmp (p, "pointer-arith"))
  465.     warn_pointer_arith = setting;
  466.       else if (!strcmp (p, "strict-prototypes"))
  467.     warn_strict_prototypes = setting;
  468.       else if (!strcmp (p, "missing-prototypes"))
  469.     warn_missing_prototypes = setting;
  470.       else if (!strcmp (p, "redundant-decls"))
  471.     warn_redundant_decls = setting;
  472.       else if (!strcmp (p, "missing-braces"))
  473.     warn_missing_braces = setting;
  474.       else if (!strcmp (p, "format"))
  475.     warn_format = setting;
  476.       else if (!strcmp (p, "conversion"))
  477.     warn_conversion = setting;
  478.       else if (!strcmp (p, "parentheses"))
  479.     warn_parentheses = setting;
  480.       else if (!strcmp (p, "comment"))
  481.     ;            /* cpp handles this one.  */
  482.       else if (!strcmp (p, "comments"))
  483.     ;            /* cpp handles this one.  */
  484.       else if (!strcmp (p, "trigraphs"))
  485.     ;            /* cpp handles this one.  */
  486.       else if (!strcmp (p, "import"))
  487.     ;            /* cpp handles this one.  */
  488.       else if (!strcmp (p, "all"))
  489.     {
  490.       extra_warnings = setting;
  491.       explicit_warn_return_type = setting;
  492.       warn_unused = setting;
  493.       warn_implicit = setting;
  494.       warn_ctor_dtor_privacy = setting;
  495.       warn_switch = setting;
  496.       warn_missing_braces = setting;
  497.       /* We save the value of warn_uninitialized, since if they put
  498.          -Wuninitialized on the command line, we need to generate a
  499.          warning about not using it without also specifying -O.  */
  500.       if (warn_uninitialized != 1)
  501.         warn_uninitialized = (setting ? 2 : 0);
  502.       warn_template_debugging = setting;
  503. #if 1 /* Why was this disabled?  -jason */
  504.       warn_enum_clash = setting;
  505. #endif
  506.     }
  507.  
  508.       else if (!strcmp (p, "overloaded-virtual"))
  509.     warn_overloaded_virtual = setting;
  510.       else if (!strcmp (p, "enum-clash"))
  511.     warn_enum_clash = setting;
  512.       else return 0;
  513.     }
  514.   else if (!strcmp (p, "-ansi"))
  515.     flag_no_asm = 1, dollars_in_ident = 0, flag_ansi = 1;
  516. #ifdef SPEW_DEBUG
  517.   /* Undocumented, only ever used when you're invoking cc1plus by hand, since
  518.      it's probably safe to assume no sane person would ever want to use this
  519.      under normal circumstances.  */
  520.   else if (!strcmp (p, "-spew-debug"))
  521.     spew_debug = 1;
  522. #endif
  523.   else
  524.     return 0;
  525.  
  526.   return 1;
  527. }
  528.  
  529. /* Incorporate `const' and `volatile' qualifiers for member functions.
  530.    FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
  531.    QUALS is a list of qualifiers.  */
  532. tree
  533. grok_method_quals (ctype, function, quals)
  534.      tree ctype, function, quals;
  535. {
  536.   tree fntype = TREE_TYPE (function);
  537.   tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
  538.  
  539.   do
  540.     {
  541.       extern tree ridpointers[];
  542.  
  543.       if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
  544.     {
  545.       if (TYPE_READONLY (ctype))
  546.         error ("duplicate `%s' %s",
  547.            IDENTIFIER_POINTER (TREE_VALUE (quals)),
  548.            (TREE_CODE (function) == FUNCTION_DECL
  549.             ? "for member function" : "in type declaration"));
  550.       ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
  551.       build_pointer_type (ctype);
  552.     }
  553.       else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
  554.     {
  555.       if (TYPE_VOLATILE (ctype))
  556.         error ("duplicate `%s' %s",
  557.            IDENTIFIER_POINTER (TREE_VALUE (quals)),
  558.            (TREE_CODE (function) == FUNCTION_DECL
  559.             ? "for member function" : "in type declaration"));
  560.       ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
  561.       build_pointer_type (ctype);
  562.     }
  563.       else
  564.     my_friendly_abort (20);
  565.       quals = TREE_CHAIN (quals);
  566.     }
  567.   while (quals);
  568.   fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
  569.                     (TREE_CODE (fntype) == METHOD_TYPE
  570.                      ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
  571.                      : TYPE_ARG_TYPES (fntype)));
  572.   if (raises)
  573.     fntype = build_exception_variant (ctype, fntype, raises);
  574.  
  575.   TREE_TYPE (function) = fntype;
  576.   return ctype;
  577. }
  578.  
  579. /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
  580.    It leaves DECL_ASSEMBLER_NAMEs with the correct value.  */
  581. /* This does not yet work with user defined conversion operators
  582.    It should.  */
  583. static void
  584. substitute_nice_name (decl)
  585.      tree decl;
  586. {
  587.   if (DECL_NAME (decl) && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE)
  588.     {
  589.       char *n = decl_as_string (DECL_NAME (decl), 1);
  590.       if (n[strlen (n) - 1] == ' ')
  591.     n[strlen (n) - 1] = 0;
  592.       DECL_NAME (decl) = get_identifier (n);
  593.     }
  594. }
  595.  
  596. /* Warn when -fexternal-templates is used and #pragma
  597.    interface/implementation is not used all the times it should be,
  598.    inform the user.  */
  599. void
  600. warn_if_unknown_interface ()
  601. {
  602.   static int already_warned = 0;
  603.   if (++already_warned == 1)
  604.     warning ("templates that are built with -fexternal-templates should be in files that have #pragma interface/implementation");
  605. }
  606.  
  607. /* A subroutine of the parser, to handle a component list.  */
  608. tree
  609. grok_x_components (specs, components)
  610.      tree specs, components;
  611. {
  612.   register tree t, x;
  613.  
  614.   /* We just got some friends.  They have been recorded elsewhere.  */
  615.   if (components == void_type_node)
  616.     return NULL_TREE;
  617.  
  618.   if (components == NULL_TREE)
  619.     {
  620.       t = groktypename (build_decl_list (specs, NULL_TREE));
  621.  
  622.       if (t == NULL_TREE)
  623.     {
  624.       error ("error in component specification");
  625.       return NULL_TREE;
  626.     }
  627.  
  628.       switch (TREE_CODE (t))
  629.     {
  630.     case VAR_DECL:
  631.       /* Static anonymous unions come out as VAR_DECLs.  */
  632.       if (TREE_CODE (TREE_TYPE (t)) == UNION_TYPE
  633.           && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t))))
  634.         return t;
  635.  
  636.       /* We return SPECS here, because in the parser it was ending
  637.          up with not doing anything to $$, which is what SPECS
  638.          represents.  */
  639.       return specs;
  640.       break;
  641.  
  642.     case RECORD_TYPE:
  643.       /* This code may be needed for UNION_TYPEs as
  644.          well.  */
  645.       if (TYPE_LANG_SPECIFIC (t)
  646.           && CLASSTYPE_DECLARED_EXCEPTION (t))
  647.         shadow_tag (specs);
  648.       return NULL_TREE;
  649.       break;
  650.  
  651.     case UNION_TYPE:
  652.     case ENUMERAL_TYPE:
  653.       if (TREE_CODE (t) == UNION_TYPE
  654.           && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
  655.         x = build_lang_field_decl (FIELD_DECL,
  656.                        NULL_TREE, t);
  657.       else if (TREE_CODE (t) == ENUMERAL_TYPE)
  658.         x = grok_enum_decls (t, NULL_TREE);
  659.       else
  660.         x = NULL_TREE;
  661.       return x;
  662.       break;
  663.  
  664.     default:
  665.       if (t != void_type_node)
  666.         error ("empty component declaration");
  667.       return NULL_TREE;
  668.     }
  669.     }
  670.   else
  671.     {
  672.       t = TREE_TYPE (components);
  673.       if (TREE_CODE (t) == ENUMERAL_TYPE && TREE_NONLOCAL_FLAG (t))
  674.     return grok_enum_decls (t, components);
  675.       else
  676.     return components;
  677.     }
  678. }
  679.  
  680. /* Classes overload their constituent function names automatically.
  681.    When a function name is declared in a record structure,
  682.    its name is changed to it overloaded name.  Since names for
  683.    constructors and destructors can conflict, we place a leading
  684.    '$' for destructors.
  685.  
  686.    CNAME is the name of the class we are grokking for.
  687.  
  688.    FUNCTION is a FUNCTION_DECL.  It was created by `grokdeclarator'.
  689.  
  690.    FLAGS contains bits saying what's special about today's
  691.    arguments.  1 == DESTRUCTOR.  2 == OPERATOR.
  692.  
  693.    If FUNCTION is a destructor, then we must add the `auto-delete' field
  694.    as a second parameter.  There is some hair associated with the fact
  695.    that we must "declare" this variable in the manner consistent with the
  696.    way the rest of the arguments were declared.
  697.  
  698.    QUALS are the qualifiers for the this pointer.  */
  699.  
  700. void
  701. grokclassfn (ctype, cname, function, flags, quals)
  702.      tree ctype, cname, function;
  703.      enum overload_flags flags;
  704.      tree quals;
  705. {
  706.   tree fn_name = DECL_NAME (function);
  707.   tree arg_types;
  708.   tree parm;
  709.  
  710.   if (fn_name == NULL_TREE)
  711.     {
  712.       error ("name missing for member function");
  713.       fn_name = get_identifier ("<anonymous>");
  714.       DECL_NAME (function) = fn_name;
  715.     }
  716.  
  717.   if (quals)
  718.     ctype = grok_method_quals (ctype, function, quals);
  719.  
  720.   arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
  721.   if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
  722.     {
  723.       /* Must add the class instance variable up front.  */
  724.       /* Right now we just make this a pointer.  But later
  725.      we may wish to make it special.  */
  726.       tree type = TREE_VALUE (arg_types);
  727.  
  728.       if (flags == DTOR_FLAG)
  729.     type = TYPE_MAIN_VARIANT (type);
  730.       else if (DECL_CONSTRUCTOR_P (function))
  731.     {
  732.       if (TYPE_USES_VIRTUAL_BASECLASSES (ctype))
  733.         {
  734.           DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1;
  735.           /* In this case we need "in-charge" flag saying whether
  736.          this constructor is responsible for initialization
  737.          of virtual baseclasses or not.  */
  738.           parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
  739.           /* Mark the artificial `__in_chrg' parameter as "artificial".  */
  740.           DECL_SOURCE_LINE (parm) = 0;
  741.           DECL_ARG_TYPE (parm) = integer_type_node;
  742.           DECL_REGISTER (parm) = 1;
  743.           TREE_CHAIN (parm) = last_function_parms;
  744.           last_function_parms = parm;
  745.         }
  746.     }
  747.  
  748.       parm = build_decl (PARM_DECL, this_identifier, type);
  749.       /* Mark the artificial `this' parameter as "artificial".  */
  750.       DECL_SOURCE_LINE (parm) = 0;
  751.       DECL_ARG_TYPE (parm) = type;
  752.       /* We can make this a register, so long as we don't
  753.      accidentally complain if someone tries to take its address.  */
  754.       DECL_REGISTER (parm) = 1;
  755. #if 0
  756.       /* it is wrong to flag the object as readonly, when
  757.      flag_this_is_variable is 0. */
  758.       if (flags != DTOR_FLAG
  759.       && (flag_this_is_variable <= 0 || TYPE_READONLY (type)))
  760. #else
  761.       if (flags != DTOR_FLAG && TYPE_READONLY (type))
  762. #endif
  763.     TREE_READONLY (parm) = 1;
  764.       TREE_CHAIN (parm) = last_function_parms;
  765.       last_function_parms = parm;
  766.     }
  767.  
  768.   if (flags == DTOR_FLAG)
  769.     {
  770.       char *buf, *dbuf;
  771.       tree const_integer_type = build_type_variant (integer_type_node, 1, 0);
  772.       int len = sizeof (DESTRUCTOR_DECL_PREFIX)-1;
  773.  
  774.       arg_types = hash_tree_chain (const_integer_type, void_list_node);
  775.       TREE_SIDE_EFFECTS (arg_types) = 1;
  776.       /* Build the overload name.  It will look like `7Example'.  */
  777.       if (IDENTIFIER_TYPE_VALUE (cname))
  778.     dbuf = build_overload_name (IDENTIFIER_TYPE_VALUE (cname), 1, 1);
  779.       else if (IDENTIFIER_LOCAL_VALUE (cname))
  780.     dbuf = build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname)), 1, 1);
  781.       else
  782.       /* Using ctype fixes the `X::Y::~Y()' crash.  The cname has no type when
  783.      it's defined out of the class definition, since poplevel_class wipes
  784.      it out.  This used to be internal error 346.  */
  785.     dbuf = build_overload_name (ctype, 1, 1);
  786.       buf = (char *) alloca (strlen (dbuf) + sizeof (DESTRUCTOR_DECL_PREFIX));
  787.       bcopy (DESTRUCTOR_DECL_PREFIX, buf, len);
  788.       buf[len] = '\0';
  789.       strcat (buf, dbuf);
  790.       DECL_ASSEMBLER_NAME (function) = get_identifier (buf);
  791.       parm = build_decl (PARM_DECL, in_charge_identifier, const_integer_type);
  792.       /* Mark the artificial `__in_chrg' parameter as "artificial".  */
  793.       DECL_SOURCE_LINE (parm) = 0;
  794.       TREE_USED (parm) = 1;
  795. #if 0
  796.       /* We don't need to mark the __in_chrg parameter itself as `const'
  797.       since its type is already `const int'.  In fact we MUST NOT mark
  798.       it as `const' cuz that will screw up the debug info (causing it
  799.       to say that the type of __in_chrg is `const const int').  */
  800.       TREE_READONLY (parm) = 1;
  801. #endif
  802.       DECL_ARG_TYPE (parm) = const_integer_type;
  803.       /* This is the same chain as DECL_ARGUMENTS (...).  */
  804.       TREE_CHAIN (last_function_parms) = parm;
  805.  
  806.       TREE_TYPE (function) = build_cplus_method_type (ctype, void_type_node,
  807.                               arg_types);
  808.       TYPE_HAS_DESTRUCTOR (ctype) = 1;
  809.     }
  810.   else
  811.     {
  812.       tree these_arg_types;
  813.  
  814.       if (DECL_CONSTRUCTOR_FOR_VBASE_P (function))
  815.     {
  816.       arg_types = hash_tree_chain (integer_type_node,
  817.                        TREE_CHAIN (arg_types));
  818.       TREE_TYPE (function)
  819.         = build_cplus_method_type (ctype,
  820.                        TREE_TYPE (TREE_TYPE (function)),
  821.                        arg_types);
  822.       arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
  823.     }
  824.  
  825.       these_arg_types = arg_types;
  826.  
  827.       if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
  828.     /* Only true for static member functions.  */
  829.     these_arg_types = hash_tree_chain (TYPE_POINTER_TO (ctype), arg_types);
  830.  
  831.       DECL_ASSEMBLER_NAME (function)
  832.     = build_decl_overload (fn_name, these_arg_types,
  833.                    1 + DECL_CONSTRUCTOR_P (function));
  834.  
  835. #if 0
  836.       /* This code is going into the compiler, but currently, it makes
  837.      libg++/src/Interger.cc not compile.  The problem is that the nice name
  838.      winds up going into the symbol table, and conversion operations look
  839.      for the manged name.  */
  840.       substitute_nice_name (function);
  841. #endif
  842.     }
  843.  
  844.   DECL_ARGUMENTS (function) = last_function_parms;
  845.   /* First approximations.  */
  846.   DECL_CONTEXT (function) = ctype;
  847.   DECL_CLASS_CONTEXT (function) = ctype;
  848. }
  849.  
  850. /* Work on the expr used by alignof (this is only called by the parser).  */
  851. tree
  852. grok_alignof (expr)
  853.      tree expr;
  854. {
  855.   tree best, t;
  856.   int bestalign;
  857.  
  858.   if (TREE_CODE (expr) == COMPONENT_REF
  859.       && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
  860.     error ("`__alignof__' applied to a bit-field");
  861.  
  862.   if (TREE_CODE (expr) == INDIRECT_REF)
  863.     {
  864.       best = t = TREE_OPERAND (expr, 0);
  865.       bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
  866.  
  867.       while (TREE_CODE (t) == NOP_EXPR
  868.          && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
  869.     {
  870.       int thisalign;
  871.       t = TREE_OPERAND (t, 0);
  872.       thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
  873.       if (thisalign > bestalign)
  874.         best = t, bestalign = thisalign;
  875.     }
  876.       return c_alignof (TREE_TYPE (TREE_TYPE (best)));
  877.     }
  878.   else
  879.     {
  880.       /* ANSI says arrays and fns are converted inside comma.
  881.      But we can't convert them in build_compound_expr
  882.      because that would break commas in lvalues.
  883.      So do the conversion here if operand was a comma.  */
  884.       if (TREE_CODE (expr) == COMPOUND_EXPR
  885.       && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
  886.           || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
  887.     expr = default_conversion (expr);
  888.       return c_alignof (TREE_TYPE (expr));
  889.     }
  890. }
  891.  
  892. /* Create an ARRAY_REF, checking for the user doing things backwards
  893.    along the way.  */
  894. tree
  895. grok_array_decl (array_expr, index_exp)
  896.      tree array_expr, index_exp;
  897. {
  898.   tree type = TREE_TYPE (array_expr);
  899.  
  900.   if (type == error_mark_node || index_exp == error_mark_node)
  901.     return error_mark_node;
  902.   if (type == NULL_TREE)
  903.     {
  904.       /* Something has gone very wrong.  Assume we are mistakenly reducing
  905.      an expression instead of a declaration.  */
  906.       error ("parser may be lost: is there a '{' missing somewhere?");
  907.       return NULL_TREE;
  908.     }
  909.  
  910.   if (TREE_CODE (type) == OFFSET_TYPE
  911.       || TREE_CODE (type) == REFERENCE_TYPE)
  912.     type = TREE_TYPE (type);
  913.  
  914.   /* If they have an `operator[]', use that.  */
  915.   if (TYPE_LANG_SPECIFIC (type)
  916.       && TYPE_OVERLOADS_ARRAY_REF (type))
  917.     return build_opfncall (ARRAY_REF, LOOKUP_NORMAL,
  918.              array_expr, index_exp, NULL_TREE);
  919.  
  920.   /* Otherwise, create an ARRAY_REF for a pointer or array type.  */
  921.   if (TREE_CODE (type) == POINTER_TYPE
  922.       || TREE_CODE (type) == ARRAY_TYPE)
  923.     return build_array_ref (array_expr, index_exp);
  924.  
  925.   /* Woops, looks like they did something like `5[a]' instead of `a[5]'.
  926.      We don't emit a warning or error for this, since it's allowed
  927.      by ARM $8.2.4.  */
  928.  
  929.   type = TREE_TYPE (index_exp);
  930.  
  931.   if (TREE_CODE (type) == OFFSET_TYPE
  932.       || TREE_CODE (type) == REFERENCE_TYPE)
  933.     type = TREE_TYPE (type);
  934.  
  935.   if (TYPE_LANG_SPECIFIC (type)
  936.       && TYPE_OVERLOADS_ARRAY_REF (type))
  937.     error ("array expression backwards");
  938.   else if (TREE_CODE (type) == POINTER_TYPE
  939.        || TREE_CODE (type) == ARRAY_TYPE)
  940.     return build_array_ref (index_exp, array_expr);
  941.   else
  942.     error("`[]' applied to non-pointer type");
  943.  
  944.   /* We gave an error, so give an error.  Huh?  */
  945.   return error_mark_node;
  946. }
  947.  
  948. /* Given the cast expression EXP, checking out its validity.   Either return
  949.    an error_mark_node if there was an unavoidable error, return a cast to
  950.    void for trying to delete a pointer w/ the value 0, or return the
  951.    call to delete.  If DOING_VEC is 1, we handle things differently
  952.    for doing an array delete.  If DOING_VEC is 2, they gave us the
  953.    array size as an argument to delete.
  954.    Implements ARM $5.3.4.  This is called from the parser.  */
  955. tree
  956. delete_sanity (exp, size, doing_vec)
  957.      tree exp, size;
  958.      int doing_vec;
  959. {
  960.   tree t = stabilize_reference (convert_from_reference (exp));
  961.   tree type = TREE_TYPE (t);
  962.   enum tree_code code = TREE_CODE (type);
  963.   /* For a regular vector delete (aka, no size argument) we will pass
  964.      this down as a NULL_TREE into build_vec_delete.  */
  965.   tree maxindex = NULL_TREE;
  966.   /* This is used for deleting arrays.  */
  967.   tree elt_size;
  968.  
  969.   switch (doing_vec)
  970.     {
  971.     case 2:
  972.       maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
  973.       if (! flag_traditional)
  974.     pedwarn ("ANSI C++ forbids array size in vector delete");
  975.       /* Fall through.  */
  976.     case 1:
  977.       elt_size = c_sizeof (type);
  978.       break;
  979.     default:
  980.       if (code != POINTER_TYPE)
  981.     {
  982.       cp_error ("type `%#T' argument given to `delete', expected pointer",
  983.             type);
  984.       return error_mark_node;
  985.     }
  986.  
  987.       /* Deleting a pointer with the value zero is legal and has no effect.  */
  988.       if (integer_zerop (t))
  989.     return build1 (NOP_EXPR, void_type_node, t);
  990.     }
  991.  
  992.   /* You can't delete a pointer to constant.  */
  993.   if (code == POINTER_TYPE && TREE_READONLY (TREE_TYPE (type)))
  994.     {
  995.       error ("`const *' cannot be deleted");
  996.       return error_mark_node;
  997.     }
  998.  
  999.   /* If the type has no destructor, then we should build a regular
  1000.      delete, instead of a vector delete.  Otherwise, we would end
  1001.      up passing a bogus offset into __builtin_delete, which is
  1002.      not expecting it.  */ 
  1003.   if (doing_vec
  1004.       && TREE_CODE (type) == POINTER_TYPE
  1005.       && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type)))
  1006.     doing_vec = 0;
  1007.  
  1008.   if (doing_vec)
  1009.     return build_vec_delete (t, maxindex, elt_size, NULL_TREE,
  1010.                  integer_one_node, integer_two_node);
  1011.   else
  1012.     return build_delete (type, t, integer_three_node,
  1013.              LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE,
  1014.              TYPE_HAS_DESTRUCTOR (TREE_TYPE (type)));
  1015. }
  1016.  
  1017. /* Sanity check: report error if this function FUNCTION is not
  1018.    really a member of the class (CTYPE) it is supposed to belong to.
  1019.    CNAME is the same here as it is for grokclassfn above.  */
  1020.  
  1021. void
  1022. check_classfn (ctype, cname, function)
  1023.      tree ctype, cname, function;
  1024. {
  1025.   tree fn_name = DECL_NAME (function);
  1026.   tree fndecl;
  1027.   int need_quotes = 0;
  1028.   tree method_vec = CLASSTYPE_METHOD_VEC (ctype);
  1029.   tree *methods = 0;
  1030.   tree *end = 0;
  1031.  
  1032.   if (method_vec != 0)
  1033.     {
  1034.       methods = &TREE_VEC_ELT (method_vec, 0);
  1035.       end = TREE_VEC_END (method_vec);
  1036.  
  1037.       /* First suss out ctors and dtors.  */
  1038.       if (*methods && fn_name == cname)
  1039.     goto got_it;
  1040.  
  1041.       while (++methods != end)
  1042.     {
  1043.       if (fn_name == DECL_NAME (*methods))
  1044.         {
  1045.         got_it:
  1046.           fndecl = *methods;
  1047.           while (fndecl)
  1048.         {
  1049.           if (DECL_ASSEMBLER_NAME (function) == DECL_ASSEMBLER_NAME (fndecl))
  1050.             return;
  1051.           fndecl = DECL_CHAIN (fndecl);
  1052.         }
  1053.           break;        /* loser */
  1054.         }
  1055.     }
  1056.     }
  1057.  
  1058.   if (methods != end)
  1059.     cp_error ("argument list for `%D' does not match any in class `%T'",
  1060.           fn_name, ctype);
  1061.   else
  1062.     {
  1063.       methods = 0;
  1064.       cp_error ("no `%D' member function declared in class `%T'",
  1065.         fn_name, ctype);
  1066.     }
  1067.  
  1068.   /* If we did not find the method in the class, add it to
  1069.      avoid spurious errors.  */
  1070.   add_method (ctype, methods, function);
  1071. }
  1072.  
  1073. /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
  1074.    of a structure component, returning a FIELD_DECL node.
  1075.    QUALS is a list of type qualifiers for this decl (such as for declaring
  1076.    const member functions).
  1077.  
  1078.    This is done during the parsing of the struct declaration.
  1079.    The FIELD_DECL nodes are chained together and the lot of them
  1080.    are ultimately passed to `build_struct' to make the RECORD_TYPE node.
  1081.  
  1082.    C++:
  1083.  
  1084.    If class A defines that certain functions in class B are friends, then
  1085.    the way I have set things up, it is B who is interested in permission
  1086.    granted by A.  However, it is in A's context that these declarations
  1087.    are parsed.  By returning a void_type_node, class A does not attempt
  1088.    to incorporate the declarations of the friends within its structure.
  1089.  
  1090.    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
  1091.    CHANGES TO CODE IN `start_method'.  */
  1092.  
  1093. tree
  1094. grokfield (declarator, declspecs, raises, init, asmspec_tree)
  1095.      tree declarator, declspecs, raises, init, asmspec_tree;
  1096. {
  1097.   register tree value;
  1098.   char *asmspec = 0;
  1099.  
  1100.   /* Convert () initializers to = initializers.  */
  1101.   if (init == NULL_TREE && declarator != NULL_TREE
  1102.       && TREE_CODE (declarator) == CALL_EXPR
  1103.       && TREE_OPERAND (declarator, 0)
  1104.       && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
  1105.       || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
  1106.       && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
  1107.     {
  1108.       init = TREE_OPERAND (declarator, 1);
  1109.       declarator = TREE_OPERAND (declarator, 0);
  1110.     }
  1111.  
  1112.   if (init
  1113.       && TREE_CODE (init) == TREE_LIST
  1114.       && TREE_VALUE (init) == error_mark_node
  1115.       && TREE_CHAIN (init) == NULL_TREE)
  1116.     init = NULL_TREE;
  1117.  
  1118.   value = grokdeclarator (declarator, declspecs, FIELD, init != 0, raises);
  1119.   if (! value)
  1120.     return NULL_TREE; /* friends went bad.  */
  1121.  
  1122.   /* Pass friendly classes back.  */
  1123.   if (TREE_CODE (value) == VOID_TYPE)
  1124.     return void_type_node;
  1125.  
  1126.   if (DECL_NAME (value) != NULL_TREE
  1127.       && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
  1128.       && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
  1129.     cp_error ("member `%D' conflicts with virtual function table field name", value);
  1130.  
  1131.   /* Stash away type declarations.  */
  1132.   if (TREE_CODE (value) == TYPE_DECL)
  1133.     {
  1134.       DECL_NONLOCAL (value) = 1;
  1135.       CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
  1136. #if !NEW_CLASS_SCOPING
  1137.       set_identifier_type_value (DECL_NAME (value), TREE_TYPE (value));
  1138. #endif
  1139.       pushdecl_class_level (value);
  1140.       return value;
  1141.     }
  1142.  
  1143.   if (DECL_IN_AGGR_P (value))
  1144.     {
  1145.       cp_error ("`%D' is already defined in the class %T", value,
  1146.           DECL_CONTEXT (value));
  1147.       return void_type_node;
  1148.     }
  1149.  
  1150.   if (flag_cadillac)
  1151.     cadillac_start_decl (value);
  1152.  
  1153.   if (asmspec_tree)
  1154.     asmspec = TREE_STRING_POINTER (asmspec_tree);
  1155.  
  1156.   if (init)
  1157.     {
  1158.       if (TREE_CODE (value) == FUNCTION_DECL)
  1159.     {
  1160.       grok_function_init (value, init);
  1161.       init = NULL_TREE;
  1162.     }
  1163.       else if (pedantic)
  1164.     {
  1165.       if (DECL_NAME (value))
  1166.         pedwarn ("ANSI C++ forbids initialization of member `%s'",
  1167.              IDENTIFIER_POINTER (DECL_NAME (value)));
  1168.       else
  1169.         pedwarn ("ANSI C++ forbids initialization of fields");
  1170.  
  1171.       init = NULL_TREE;
  1172.     }
  1173.       else
  1174.     {
  1175.       /* We allow initializers to become parameters to base initializers.  */
  1176.       if (TREE_CODE (init) == TREE_LIST)
  1177.         {
  1178.           if (TREE_CHAIN (init) == NULL_TREE)
  1179.         init = TREE_VALUE (init);
  1180.           else
  1181.         init = digest_init (TREE_TYPE (value), init, (tree *)0);
  1182.         }
  1183.       
  1184.       if (TREE_CODE (init) == CONST_DECL)
  1185.         init = DECL_INITIAL (init);
  1186.       else if (TREE_READONLY_DECL_P (init))
  1187.         init = decl_constant_value (init);
  1188.       else if (TREE_CODE (init) == CONSTRUCTOR)
  1189.         init = digest_init (TREE_TYPE (value), init, (tree *)0);
  1190.       my_friendly_assert (TREE_PERMANENT (init), 192);
  1191.       if (init == error_mark_node)
  1192.         /* We must make this look different than `error_mark_node'
  1193.            because `decl_const_value' would mis-interpret it
  1194.            as only meaning that this VAR_DECL is defined.  */
  1195.         init = build1 (NOP_EXPR, TREE_TYPE (value), init);
  1196.       else if (! TREE_CONSTANT (init))
  1197.         {
  1198.           /* We can allow references to things that are effectively
  1199.          static, since references are initialized with the address.  */
  1200.           if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
  1201.           || (TREE_STATIC (init) == 0
  1202.               && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
  1203.               || DECL_EXTERNAL (init) == 0)))
  1204.         {
  1205.           error ("field initializer is not constant");
  1206.           init = error_mark_node;
  1207.         }
  1208.         }
  1209.     }
  1210.     }
  1211.  
  1212.   /* The corresponding pop_obstacks is in finish_decl.  */
  1213.   push_obstacks_nochange ();
  1214.  
  1215.   if (TREE_CODE (value) == VAR_DECL)
  1216.     {
  1217.       /* We cannot call pushdecl here, because that would
  1218.      fill in the value of our TREE_CHAIN.  Instead, we
  1219.      modify finish_decl to do the right thing, namely, to
  1220.      put this decl out straight away.  */
  1221.       if (TREE_STATIC (value))
  1222.     {
  1223.       /* current_class_type can be NULL_TREE in case of error.  */
  1224.       if (asmspec == 0 && current_class_type)
  1225.         {
  1226.           tree name;
  1227.           char *buf, *buf2;
  1228.  
  1229.           buf2 = build_overload_name (current_class_type, 1, 1);
  1230.           buf = (char *)alloca (IDENTIFIER_LENGTH (DECL_NAME (value))
  1231.                     + sizeof (STATIC_NAME_FORMAT)
  1232.                     + strlen (buf2));
  1233.           sprintf (buf, STATIC_NAME_FORMAT, buf2,
  1234.                IDENTIFIER_POINTER (DECL_NAME (value)));
  1235.           name = get_identifier (buf);
  1236.           TREE_PUBLIC (value) = 1;
  1237.           DECL_INITIAL (value) = error_mark_node;
  1238.           DECL_ASSEMBLER_NAME (value) = name;
  1239.         }
  1240.       pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
  1241.  
  1242.       /* Static consts need not be initialized in the class definition.  */
  1243.       if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
  1244.         {
  1245.           static int explanation = 0;
  1246.  
  1247.           error ("initializer invalid for static member with constructor");
  1248.           if (explanation++ == 0)
  1249.         error ("(you really want to initialize it separately)");
  1250.           init = 0;
  1251.         }
  1252.       /* Force the compiler to know when an uninitialized static
  1253.          const member is being used.  */
  1254.       if (TYPE_READONLY (value) && init == 0)
  1255.         TREE_USED (value) = 1;
  1256.     }
  1257.       DECL_INITIAL (value) = init;
  1258.       DECL_IN_AGGR_P (value) = 1;
  1259.  
  1260.       finish_decl (value, init, asmspec_tree, 1);
  1261.       pushdecl_class_level (value);
  1262.       return value;
  1263.     }
  1264.   if (TREE_CODE (value) == FIELD_DECL)
  1265.     {
  1266.       if (asmspec)
  1267.     DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
  1268.       if (DECL_INITIAL (value) == error_mark_node)
  1269.     init = error_mark_node;
  1270.       finish_decl (value, init, asmspec_tree, 1);
  1271.       DECL_INITIAL (value) = init;
  1272.       DECL_IN_AGGR_P (value) = 1;
  1273.       return value;
  1274.     }
  1275.   if (TREE_CODE (value) == FUNCTION_DECL)
  1276.     {
  1277.       /* grokdeclarator defers setting this.  */
  1278.       TREE_PUBLIC (value) = 1;
  1279.       if (DECL_CHAIN (value) != NULL_TREE)
  1280.     {
  1281.       /* Need a fresh node here so that we don't get circularity
  1282.          when we link these together.  */
  1283.       value = copy_node (value);
  1284.       /* When does this happen?  */
  1285.       my_friendly_assert (init == NULL_TREE, 193);
  1286.     }
  1287.       finish_decl (value, init, asmspec_tree, 1);
  1288.  
  1289.       /* Pass friends back this way.  */
  1290.       if (DECL_FRIEND_P (value))
  1291.     return void_type_node;
  1292.  
  1293.       DECL_IN_AGGR_P (value) = 1;
  1294.       return value;
  1295.     }
  1296.   my_friendly_abort (21);
  1297.   /* NOTREACHED */
  1298.   return NULL_TREE;
  1299. }
  1300.  
  1301. /* Like `grokfield', but for bitfields.
  1302.    WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node.  */
  1303.  
  1304. tree
  1305. grokbitfield (declarator, declspecs, width)
  1306.      tree declarator, declspecs, width;
  1307. {
  1308.   register tree value = grokdeclarator (declarator, declspecs, BITFIELD, 0, NULL_TREE);
  1309.  
  1310.   if (! value) return NULL_TREE; /* friends went bad.  */
  1311.  
  1312.   /* Pass friendly classes back.  */
  1313.   if (TREE_CODE (value) == VOID_TYPE)
  1314.     return void_type_node;
  1315.  
  1316.   if (TREE_CODE (value) == TYPE_DECL)
  1317.     {
  1318.       cp_error ("cannot declare `%D' to be a bitfield type", value);
  1319.       return NULL_TREE;
  1320.     }
  1321.  
  1322.   if (DECL_IN_AGGR_P (value))
  1323.     {
  1324.       cp_error ("`%D' is already defined in the class %T", value,
  1325.           DECL_CONTEXT (value));
  1326.       return void_type_node;
  1327.     }
  1328.  
  1329.   GNU_xref_member (current_class_name, value);
  1330.  
  1331.   if (TREE_STATIC (value))
  1332.     {
  1333.       cp_error ("static member `%D' cannot be a bitfield", value);
  1334.       return NULL_TREE;
  1335.     }
  1336.   finish_decl (value, NULL_TREE, NULL_TREE, 0);
  1337.  
  1338.   if (width != error_mark_node)
  1339.     {
  1340.       /* detect invalid field size.  */
  1341.       if (TREE_CODE (width) == CONST_DECL)
  1342.     width = DECL_INITIAL (width);
  1343.       else if (TREE_READONLY_DECL_P (width))
  1344.     width = decl_constant_value (width);
  1345.       if (TREE_CODE (width) != INTEGER_CST)
  1346.     {
  1347.       cp_error ("structure field `%D' width not an integer constant",
  1348.               value);
  1349.       DECL_INITIAL (value) = NULL_TREE;
  1350.     }
  1351.       else
  1352.     {
  1353.       constant_expression_warning (width);
  1354.       DECL_INITIAL (value) = width;
  1355.       DECL_BIT_FIELD (value) = 1;
  1356.     }
  1357.     }
  1358.  
  1359.   DECL_IN_AGGR_P (value) = 1;
  1360.   return value;
  1361. }
  1362.  
  1363. /* Like GROKFIELD, except that the declarator has been
  1364.    buried in DECLSPECS.  Find the declarator, and
  1365.    return something that looks like it came from
  1366.    GROKFIELD.  */
  1367. tree
  1368. groktypefield (declspecs, parmlist)
  1369.      tree declspecs;
  1370.      tree parmlist;
  1371. {
  1372.   tree spec = declspecs;
  1373.   tree prev = NULL_TREE;
  1374.  
  1375.   tree type_id = NULL_TREE;
  1376.   tree quals = NULL_TREE;
  1377.   tree lengths = NULL_TREE;
  1378.   tree decl = NULL_TREE;
  1379.  
  1380.   while (spec)
  1381.     {
  1382.       register tree id = TREE_VALUE (spec);
  1383.  
  1384.       if (TREE_CODE (spec) != TREE_LIST)
  1385.     /* Certain parse errors slip through.  For example,
  1386.        `int class ();' is not caught by the parser. Try
  1387.        weakly to recover here.  */
  1388.     return NULL_TREE;
  1389.  
  1390.       if (TREE_CODE (id) == TYPE_DECL
  1391.       || (TREE_CODE (id) == IDENTIFIER_NODE && TREE_TYPE (id)))
  1392.     {
  1393.       /* We have a constructor/destructor or
  1394.          conversion operator.  Use it.  */
  1395.       if (prev)
  1396.         TREE_CHAIN (prev) = TREE_CHAIN (spec);
  1397.       else
  1398.         declspecs = TREE_CHAIN (spec);
  1399.  
  1400.       type_id = id;
  1401.       goto found;
  1402.     }
  1403.       prev = spec;
  1404.       spec = TREE_CHAIN (spec);
  1405.     }
  1406.  
  1407.   /* Nope, we have a conversion operator to a scalar type or something
  1408.      else, that includes things like constructor declarations for
  1409.      templates.  */
  1410.   spec = declspecs;
  1411.   while (spec)
  1412.     {
  1413.       tree id = TREE_VALUE (spec);
  1414.  
  1415.       if (TREE_CODE (id) == IDENTIFIER_NODE)
  1416.     {
  1417.       if (id == ridpointers[(int)RID_INT]
  1418.           || id == ridpointers[(int)RID_DOUBLE]
  1419.           || id == ridpointers[(int)RID_FLOAT]
  1420.           || id == ridpointers[(int)RID_WCHAR])
  1421.         {
  1422.           if (type_id)
  1423.         error ("extra `%s' ignored",
  1424.                IDENTIFIER_POINTER (id));
  1425.           else
  1426.         type_id = id;
  1427.         }
  1428.       else if (id == ridpointers[(int)RID_LONG]
  1429.            || id == ridpointers[(int)RID_SHORT]
  1430.            || id == ridpointers[(int)RID_CHAR])
  1431.         {
  1432.           lengths = tree_cons (NULL_TREE, id, lengths);
  1433.         }
  1434.       else if (id == ridpointers[(int)RID_VOID])
  1435.         {
  1436.           if (type_id)
  1437.         error ("spurious `void' type ignored");
  1438.           else
  1439.         error ("conversion to `void' type invalid");
  1440.         }
  1441.       else if (id == ridpointers[(int)RID_AUTO]
  1442.            || id == ridpointers[(int)RID_REGISTER]
  1443.            || id == ridpointers[(int)RID_TYPEDEF]
  1444.            || id == ridpointers[(int)RID_CONST]
  1445.            || id == ridpointers[(int)RID_VOLATILE])
  1446.         {
  1447.           error ("type specifier `%s' used invalidly",
  1448.              IDENTIFIER_POINTER (id));
  1449.         }
  1450.       else if (id == ridpointers[(int)RID_FRIEND]
  1451.            || id == ridpointers[(int)RID_VIRTUAL]
  1452.            || id == ridpointers[(int)RID_INLINE]
  1453.            || id == ridpointers[(int)RID_UNSIGNED]
  1454.            || id == ridpointers[(int)RID_SIGNED]
  1455.            || id == ridpointers[(int)RID_STATIC]
  1456.            || id == ridpointers[(int)RID_EXTERN])
  1457.         {
  1458.           quals = tree_cons (NULL_TREE, id, quals);
  1459.         }
  1460.       else
  1461.         {
  1462.           /* Happens when we have a global typedef
  1463.          and a class-local member function with
  1464.          the same name.  */
  1465.           type_id = id;
  1466.           goto found;
  1467.         }
  1468.     }
  1469.       else if (TREE_CODE (id) == RECORD_TYPE)
  1470.     {
  1471.       type_id = TYPE_NAME (id);
  1472.       if (TREE_CODE (type_id) == TYPE_DECL)
  1473.         type_id = DECL_NAME (type_id);
  1474.       if (type_id == NULL_TREE)
  1475.         error ("identifier for aggregate type conversion omitted");
  1476.     }
  1477.       else if (TREE_CODE_CLASS (TREE_CODE (id)) == 't')
  1478.     error ("`operator' missing on conversion operator or tag missing from type");
  1479.       else
  1480.     my_friendly_abort (194);
  1481.       spec = TREE_CHAIN (spec);
  1482.     }
  1483.  
  1484.   if (type_id)
  1485.     declspecs = chainon (lengths, quals);
  1486.   else if (lengths)
  1487.     {
  1488.       if (TREE_CHAIN (lengths))
  1489.     error ("multiple length specifiers");
  1490.       type_id = ridpointers[(int)RID_INT];
  1491.       declspecs = chainon (lengths, quals);
  1492.     }
  1493.   else if (quals)
  1494.     {
  1495.       error ("no type given, defaulting to `operator int ...'");
  1496.       type_id = ridpointers[(int)RID_INT];
  1497.       declspecs = quals;
  1498.     }
  1499.   else
  1500.     return NULL_TREE;
  1501.  
  1502.  found:
  1503.   decl = grokdeclarator (build_parse_node (CALL_EXPR, type_id, parmlist, NULL_TREE),
  1504.              declspecs, FIELD, 0, NULL_TREE);
  1505.   if (decl == NULL_TREE)
  1506.     return NULL_TREE;
  1507.  
  1508.   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CHAIN (decl) != NULL_TREE)
  1509.     {
  1510.       /* Need a fresh node here so that we don't get circularity
  1511.      when we link these together.  */
  1512.       decl = copy_node (decl);
  1513.     }
  1514.  
  1515.   if (decl == void_type_node
  1516.       || (TREE_CODE (decl) == FUNCTION_DECL
  1517.       && TREE_CODE (TREE_TYPE (decl)) != METHOD_TYPE))
  1518.     /* bunch of friends.  */
  1519.     return decl;
  1520.  
  1521.   if (DECL_IN_AGGR_P (decl))
  1522.     {
  1523.       cp_error ("`%D' already defined in the class ", decl);
  1524.       return void_type_node;
  1525.     }
  1526.  
  1527.   finish_decl (decl, NULL_TREE, NULL_TREE, 0);
  1528.  
  1529.   /* If this declaration is common to another declaration
  1530.      complain about such redundancy, and return NULL_TREE
  1531.      so that we don't build a circular list.  */
  1532.   if (DECL_CHAIN (decl))
  1533.     {
  1534.       cp_error ("function `%D' declared twice in class %T", decl,
  1535.           DECL_CONTEXT (decl));
  1536.       return NULL_TREE;
  1537.     }
  1538.   DECL_IN_AGGR_P (decl) = 1;
  1539.   return decl;
  1540. }
  1541.  
  1542. /* The precedence rules of this grammar (or any other deterministic LALR
  1543.    grammar, for that matter), place the CALL_EXPR somewhere where we
  1544.    may not want it.  The solution is to grab the first CALL_EXPR we see,
  1545.    pretend that that is the one that belongs to the parameter list of
  1546.    the type conversion function, and leave everything else alone.
  1547.    We pull it out in place.
  1548.  
  1549.    CALL_REQUIRED is non-zero if we should complain if a CALL_EXPR
  1550.    does not appear in DECL.  */
  1551. tree
  1552. grokoptypename (decl, call_required)
  1553.      tree decl;
  1554.      int call_required;
  1555. {
  1556.   tree tmp, last;
  1557.  
  1558.   my_friendly_assert (TREE_CODE (decl) == TYPE_EXPR, 195);
  1559.  
  1560.   tmp = TREE_OPERAND (decl, 0);
  1561.   last = NULL_TREE;
  1562.  
  1563.   while (tmp)
  1564.     {
  1565.       switch (TREE_CODE (tmp))
  1566.     {
  1567.     case CALL_EXPR:
  1568.       {
  1569.         tree parms = TREE_OPERAND (tmp, 1);
  1570.  
  1571.         if (last)
  1572.           TREE_OPERAND (last, 0) = TREE_OPERAND (tmp, 0);
  1573.         else
  1574.           TREE_OPERAND (decl, 0) = TREE_OPERAND (tmp, 0);
  1575.  
  1576.         last = grokdeclarator (TREE_OPERAND (decl, 0),
  1577.                    TREE_TYPE (decl),
  1578.                    TYPENAME, 0, NULL_TREE);
  1579.         TREE_OPERAND (tmp, 0) = build_typename_overload (last);
  1580.         TREE_TYPE (TREE_OPERAND (tmp, 0)) = last;
  1581.  
  1582.         if (parms
  1583.         && TREE_CODE (TREE_VALUE (parms)) == TREE_LIST)
  1584.           TREE_VALUE (parms)
  1585.         = grokdeclarator (TREE_VALUE (TREE_VALUE (parms)),
  1586.                   TREE_PURPOSE (TREE_VALUE (parms)),
  1587.                   TYPENAME, 0, NULL_TREE);
  1588.         if (parms)
  1589.           {
  1590.         if (TREE_VALUE (parms) != void_type_node)
  1591.           cp_error ("`operator %T' requires empty parameter list",
  1592.                 last);
  1593.         else
  1594.           /* Canonicalize parameter lists.  */
  1595.           TREE_OPERAND (tmp, 1) = void_list_node;
  1596.           }
  1597.  
  1598.         return tmp;
  1599.       }
  1600.  
  1601.     case INDIRECT_REF:
  1602.     case ADDR_EXPR:
  1603.     case ARRAY_REF:
  1604.       break;
  1605.  
  1606.     case SCOPE_REF:
  1607.       /* This is legal when declaring a conversion to
  1608.          something of type pointer-to-member.  */
  1609.       if (TREE_CODE (TREE_OPERAND (tmp, 1)) == INDIRECT_REF)
  1610.         {
  1611.           tmp = TREE_OPERAND (tmp, 1);
  1612.         }
  1613.       else
  1614.         {
  1615. #if 0
  1616.           /* We may need to do this if grokdeclarator cannot handle this.  */
  1617.           error ("type `member of class %s' invalid return type",
  1618.              TYPE_NAME_STRING (TREE_OPERAND (tmp, 0)));
  1619.           TREE_OPERAND (tmp, 1) = build_parse_node (INDIRECT_REF, TREE_OPERAND (tmp, 1));
  1620. #endif
  1621.           tmp = TREE_OPERAND (tmp, 1);
  1622.         }
  1623.       break;
  1624.  
  1625.     default:
  1626.       my_friendly_abort (196);
  1627.     }
  1628.       last = tmp;
  1629.       tmp = TREE_OPERAND (tmp, 0);
  1630.     }
  1631.  
  1632.   last = grokdeclarator (TREE_OPERAND (decl, 0),
  1633.              TREE_TYPE (decl),
  1634.              TYPENAME, 0, NULL_TREE);
  1635.  
  1636.   if (call_required)
  1637.     cp_error ("`operator %T' construct requires parameter list", last);
  1638.  
  1639.   tmp = build_parse_node (CALL_EXPR, build_typename_overload (last),
  1640.               void_list_node, NULL_TREE);
  1641.   TREE_TYPE (TREE_OPERAND (tmp, 0)) = last;
  1642.   return tmp;
  1643. }
  1644.  
  1645. /* When a function is declared with an initializer,
  1646.    do the right thing.  Currently, there are two possibilities:
  1647.  
  1648.    class B
  1649.    {
  1650.     public:
  1651.      // initialization possibility #1.
  1652.      virtual void f () = 0;
  1653.      int g ();
  1654.    };
  1655.    
  1656.    class D1 : B
  1657.    {
  1658.     public:
  1659.      int d1;
  1660.      // error, no f ();
  1661.    };
  1662.    
  1663.    class D2 : B
  1664.    {
  1665.     public:
  1666.      int d2;
  1667.      void f ();
  1668.    };
  1669.    
  1670.    class D3 : B
  1671.    {
  1672.     public:
  1673.      int d3;
  1674.      // initialization possibility #2
  1675.      void f () = B::f;
  1676.    };
  1677.  
  1678. */
  1679.  
  1680. static void
  1681. grok_function_init (decl, init)
  1682.      tree decl;
  1683.      tree init;
  1684. {
  1685.   /* An initializer for a function tells how this function should
  1686.      be inherited.  */
  1687.   tree type = TREE_TYPE (decl);
  1688.   extern tree abort_fndecl;
  1689.  
  1690.   if (TREE_CODE (type) == FUNCTION_TYPE)
  1691.     cp_error ("initializer specified for non-member function `%D'", decl);
  1692.   else if (DECL_VINDEX (decl) == NULL_TREE)
  1693.     cp_error ("initializer specified for non-virtual method `%D'", decl);
  1694.   else if (integer_zerop (init))
  1695.     {
  1696.       /* Mark this function as being "defined".  */
  1697.       DECL_INITIAL (decl) = error_mark_node;
  1698.       /* pure virtual destructors must be defined. */
  1699.       if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
  1700.     {
  1701.       /* Give this node rtl from `abort'.  */
  1702.       DECL_RTL (decl) = DECL_RTL (abort_fndecl);
  1703.     }
  1704.       DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
  1705.     }
  1706.   else if (TREE_CODE (init) == OFFSET_REF
  1707.        && TREE_OPERAND (init, 0) == NULL_TREE
  1708.        && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE)
  1709.     {
  1710.       tree basetype = DECL_CLASS_CONTEXT (init);
  1711.       tree basefn = TREE_OPERAND (init, 1);
  1712.       if (TREE_CODE (basefn) != FUNCTION_DECL)
  1713.     cp_error ("non-method initializer invalid for method `%D'", decl);
  1714.       else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn))))
  1715.     sorry ("base member function from other than first base class");
  1716.       else
  1717.     {
  1718.       tree binfo = get_binfo (basetype, TYPE_METHOD_BASETYPE (type), 1);
  1719.       if (binfo == error_mark_node)
  1720.         ;
  1721.       else if (binfo == 0)
  1722.         error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)),
  1723.                  TYPE_METHOD_BASETYPE (type));
  1724.       else
  1725.         {
  1726.           /* Mark this function as being defined,
  1727.          and give it new rtl.  */
  1728.           DECL_INITIAL (decl) = error_mark_node;
  1729.           DECL_RTL (decl) = DECL_RTL (basefn);
  1730.         }
  1731.     }
  1732.     }
  1733.   else
  1734.     cp_error ("invalid initializer for virtual method `%D'", decl);
  1735. }
  1736.  
  1737. /* When we get a declaration of the form
  1738.  
  1739.    type cname::fname ...
  1740.  
  1741.    the node for `cname::fname' gets built here in a special way.
  1742.    Namely, we push into `cname's scope.  When this declaration is
  1743.    processed, we pop back out.  */
  1744. tree
  1745. build_push_scope (cname, name)
  1746.      tree cname;
  1747.      tree name;
  1748. {
  1749.   extern int current_class_depth;
  1750.   tree ctype, rval;
  1751.  
  1752.   if (cname == error_mark_node)
  1753.     return error_mark_node;
  1754.  
  1755.   ctype = IDENTIFIER_TYPE_VALUE (cname);
  1756.  
  1757.   if (ctype == NULL_TREE || ! IS_AGGR_TYPE (ctype))
  1758.     {
  1759.       error ("`%s' not defined as aggregate type", IDENTIFIER_POINTER (cname));
  1760.       return name;
  1761.     }
  1762.  
  1763.   rval = build_parse_node (SCOPE_REF, cname, name);
  1764.  
  1765.   /* Don't need to push the scope if we're already in it.
  1766.      We also don't need to push the scope for a ptr-to-member/method.  */
  1767.  
  1768.   if (ctype == current_class_type || TREE_CODE (name) != IDENTIFIER_NODE)
  1769.     return rval;
  1770.  
  1771.   /* We do need to push the scope in this case, since CTYPE helps
  1772.      determine subsequent intializers (i.e., Foo::Bar x = foo_enum_1;).  */
  1773.  
  1774. #if NEW_CLASS_SCOPING
  1775.   push_nested_class (ctype, 3);
  1776. #else
  1777.   pushclass (ctype, 3);
  1778. #endif
  1779.   TREE_COMPLEXITY (rval) = current_class_depth;
  1780.   return rval;
  1781. }
  1782.  
  1783. void cplus_decl_attributes (decl, attributes)
  1784.      tree decl, attributes;
  1785. {
  1786.   if (decl)
  1787.     decl_attributes (decl, attributes);
  1788. }
  1789.  
  1790. /* CONSTRUCTOR_NAME:
  1791.    Return the name for the constructor (or destructor) for the
  1792.    specified class.  Argument can be RECORD_TYPE, TYPE_DECL, or
  1793.    IDENTIFIER_NODE.  When given a template, this routine doesn't
  1794.    lose the specialization.  */
  1795. tree
  1796. constructor_name_full (thing)
  1797.      tree thing;
  1798. {
  1799.   tree t;
  1800.   if (TREE_CODE (thing) == UNINSTANTIATED_P_TYPE)
  1801.     return DECL_NAME (UPT_TEMPLATE (thing));
  1802.   if (TREE_CODE (thing) == RECORD_TYPE || TREE_CODE (thing) == UNION_TYPE)
  1803.     thing = TYPE_NAME (thing);
  1804.   if (TREE_CODE (thing) == TYPE_DECL
  1805.       || (TREE_CODE (thing) == TEMPLATE_DECL
  1806.       && DECL_TEMPLATE_IS_CLASS (thing)))
  1807.     thing = DECL_NAME (thing);
  1808.   my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197);
  1809.   return thing;
  1810. }
  1811.  
  1812. /* CONSTRUCTOR_NAME:
  1813.    Return the name for the constructor (or destructor) for the
  1814.    specified class.  Argument can be RECORD_TYPE, TYPE_DECL, or
  1815.    IDENTIFIER_NODE.  When given a template, return the plain
  1816.    unspecialized name.  */
  1817. tree
  1818. constructor_name (thing)
  1819.      tree thing;
  1820. {
  1821.   tree t;
  1822.   thing = constructor_name_full (thing);
  1823.   t = IDENTIFIER_TEMPLATE (thing);
  1824.   if (!t)
  1825.     return thing;
  1826.   t = TREE_PURPOSE (t);
  1827.   return DECL_NAME (t);
  1828. }
  1829.  
  1830. /* Cache the value of this class's main virtual function table pointer
  1831.    in a register variable.  This will save one indirection if a
  1832.    more than one virtual function call is made this function.  */
  1833. void
  1834. setup_vtbl_ptr ()
  1835. {
  1836.   extern rtx base_init_insns;
  1837.  
  1838.   if (base_init_insns == 0
  1839.       && DECL_CONSTRUCTOR_P (current_function_decl))
  1840.     emit_base_init (current_class_type, 0);
  1841.  
  1842. #if 0
  1843.   /* This has something a little wrong with it.
  1844.  
  1845.      On a sun4, code like:
  1846.  
  1847.         be L6
  1848.         ld [%i0],%o1
  1849.  
  1850.      is generated, when the below is used when -O4 is given.  The delay
  1851.      slot it filled with an instruction that is safe, when this isn't
  1852.      used, like in:
  1853.  
  1854.         be L6
  1855.         sethi %hi(LC1),%o0
  1856.         ld [%i0],%o1
  1857.  
  1858.      on code like:
  1859.  
  1860.         struct A {
  1861.           virtual void print() { printf("xxx"); }
  1862.           void f();
  1863.         };
  1864.  
  1865.         void A::f() {
  1866.           if (this) {
  1867.             print();
  1868.           } else {
  1869.             printf("0");
  1870.           }
  1871.         }
  1872.  
  1873.      And that is why this is disabled for now. (mrs)
  1874.   */
  1875.  
  1876.   if ((flag_this_is_variable & 1) == 0
  1877.       && optimize
  1878.       && current_class_type
  1879.       && CLASSTYPE_VSIZE (current_class_type)
  1880.       && ! DECL_STATIC_FUNCTION_P (current_function_decl))
  1881.     {
  1882.       tree vfield = build_vfield_ref (C_C_D, current_class_type);
  1883.       current_vtable_decl = CLASSTYPE_VTBL_PTR (current_class_type);
  1884.       DECL_RTL (current_vtable_decl) = 0;
  1885.       DECL_INITIAL (current_vtable_decl) = error_mark_node;
  1886.       /* Have to cast the initializer, since it may have come from a
  1887.      more base class then we ascribe CURRENT_VTABLE_DECL to be.  */
  1888.       finish_decl (current_vtable_decl, convert_force (TREE_TYPE (current_vtable_decl), vfield), 0, 0);
  1889.       current_vtable_decl = build_indirect_ref (current_vtable_decl, NULL_PTR);
  1890.     }
  1891.   else
  1892. #endif
  1893.     current_vtable_decl = NULL_TREE;
  1894. }
  1895.  
  1896. /* Record the existence of an addressable inline function.  */
  1897. void
  1898. mark_inline_for_output (decl)
  1899.      tree decl;
  1900. {
  1901.   if (DECL_PENDING_INLINE_INFO (decl) != 0
  1902.       && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
  1903.     {
  1904.       struct pending_inline *t = pending_inlines;
  1905.       my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198);
  1906.       while (t)
  1907.     {
  1908.       if (t == DECL_PENDING_INLINE_INFO (decl))
  1909.         break;
  1910.       t = t->next;
  1911.     }
  1912.       if (t == 0)
  1913.     {
  1914.       t = DECL_PENDING_INLINE_INFO (decl);
  1915.       t->next = pending_inlines;
  1916.       pending_inlines = t;
  1917.     }
  1918.       DECL_PENDING_INLINE_INFO (decl) = 0;
  1919.     }
  1920.   pending_addressable_inlines = perm_tree_cons (NULL_TREE, decl,
  1921.                         pending_addressable_inlines);
  1922. }
  1923.  
  1924. void
  1925. clear_temp_name ()
  1926. {
  1927.   temp_name_counter = 0;
  1928. }
  1929.  
  1930. /* Hand off a unique name which can be used for variable we don't really
  1931.    want to know about anyway, for example, the anonymous variables which
  1932.    are needed to make references work.  Declare this thing so we can use it.
  1933.    The variable created will be of type TYPE.
  1934.  
  1935.    STATICP is nonzero if this variable should be static.  */
  1936.  
  1937. tree
  1938. get_temp_name (type, staticp)
  1939.      tree type;
  1940.      int staticp;
  1941. {
  1942.   char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
  1943.   tree decl;
  1944.   int toplev = global_bindings_p ();
  1945.  
  1946.   push_obstacks_nochange ();
  1947.   if (toplev || staticp)
  1948.     {
  1949.       end_temporary_allocation ();
  1950.       sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
  1951.       decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
  1952.     }
  1953.   else
  1954.     {
  1955.       sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
  1956.       decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
  1957.     }
  1958.   TREE_USED (decl) = 1;
  1959.   TREE_STATIC (decl) = staticp;
  1960.  
  1961.   /* If this is a local variable, then lay out its rtl now.
  1962.      Otherwise, callers of this function are responsible for dealing
  1963.      with this variable's rtl.  */
  1964.   if (! toplev)
  1965.     {
  1966.       expand_decl (decl);
  1967.       expand_decl_init (decl);
  1968.     }
  1969.   pop_obstacks ();
  1970.  
  1971.   return decl;
  1972. }
  1973.  
  1974. /* Get a variable which we can use for multiple assignments.
  1975.    It is not entered into current_binding_level, because
  1976.    that breaks things when it comes time to do final cleanups
  1977.    (which take place "outside" the binding contour of the function).  */
  1978. tree
  1979. get_temp_regvar (type, init)
  1980.      tree type, init;
  1981. {
  1982.   static char buf[sizeof (AUTO_TEMP_FORMAT) + 20] = { '_' };
  1983.   tree decl;
  1984.  
  1985.   sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++);
  1986.   decl = build_decl (VAR_DECL, get_identifier (buf), type);
  1987.   TREE_USED (decl) = 1;
  1988.   DECL_REGISTER (decl) = 1;
  1989.  
  1990.   if (init)
  1991.     store_init_value (decl, init);
  1992.  
  1993.   /* We can expand these without fear, since they cannot need
  1994.      constructors or destructors.  */
  1995.   expand_decl (decl);
  1996.   expand_decl_init (decl);
  1997.  
  1998.   if (type_needs_gc_entry (type))
  1999.     DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
  2000.  
  2001.   return decl;
  2002. }
  2003.  
  2004. /* Make the macro TEMP_NAME_P available to units which do not
  2005.    include c-tree.h.  */
  2006. int
  2007. temp_name_p (decl)
  2008.      tree decl;
  2009. {
  2010.   return TEMP_NAME_P (decl);
  2011. }
  2012.  
  2013. /* Finish off the processing of a UNION_TYPE structure.
  2014.    If there are static members, then all members are
  2015.    static, and must be laid out together.  If the
  2016.    union is an anonymous union, we arrange for that
  2017.    as well.  PUBLIC_P is nonzero if this union is
  2018.    not declared static.  */
  2019. void
  2020. finish_anon_union (anon_union_decl)
  2021.      tree anon_union_decl;
  2022. {
  2023.   tree type = TREE_TYPE (anon_union_decl);
  2024.   tree field, main_decl = NULL_TREE;
  2025.   tree elems = NULL_TREE;
  2026.   int public_p = TREE_PUBLIC (anon_union_decl);
  2027.   int static_p = TREE_STATIC (anon_union_decl);
  2028.   int external_p = DECL_EXTERNAL (anon_union_decl);
  2029.  
  2030.   if ((field = TYPE_FIELDS (type)) == NULL_TREE)
  2031.     return;
  2032.  
  2033.   if (public_p)
  2034.     {
  2035.       error ("global anonymous unions must be declared static");
  2036.       return;
  2037.     }
  2038.  
  2039.   while (field)
  2040.     {
  2041.       tree decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
  2042.       /* tell `pushdecl' that this is not tentative.  */
  2043.       DECL_INITIAL (decl) = error_mark_node;
  2044.       TREE_PUBLIC (decl) = public_p;
  2045.       TREE_STATIC (decl) = static_p;
  2046.       DECL_EXTERNAL (decl) = external_p;
  2047.       decl = pushdecl (decl);
  2048.  
  2049.       /* Only write out one anon union element--choose the one that
  2050.      can hold them all.  */
  2051.       if (main_decl == NULL_TREE
  2052.       && simple_cst_equal (DECL_SIZE (decl), DECL_SIZE (anon_union_decl)))
  2053.     {
  2054.       main_decl = decl;
  2055.     }
  2056.       else
  2057.     {
  2058.       /* ??? This causes there to be no debug info written out
  2059.          about this decl.  */
  2060.       TREE_ASM_WRITTEN (decl) = 1;
  2061.     }
  2062.  
  2063.       DECL_INITIAL (decl) = NULL_TREE;
  2064.       /* If there's a cleanup to do, it belongs in the
  2065.      TREE_PURPOSE of the following TREE_LIST.  */
  2066.       elems = tree_cons (NULL_TREE, decl, elems);
  2067.       TREE_TYPE (elems) = type;
  2068.       field = TREE_CHAIN (field);
  2069.     }
  2070.   if (static_p)
  2071.     {
  2072.       make_decl_rtl (main_decl, 0, global_bindings_p ());
  2073.       DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
  2074.     }
  2075.  
  2076.   /* The following call assumes that there are never any cleanups
  2077.      for anonymous unions--a reasonable assumption.  */
  2078.   expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
  2079.  
  2080.   if (flag_cadillac)
  2081.     cadillac_finish_anon_union (anon_union_decl);
  2082. }
  2083.  
  2084. /* Finish and output a table which is generated by the compiler.
  2085.    NAME is the name to give the table.
  2086.    TYPE is the type of the table entry.
  2087.    INIT is all the elements in the table.
  2088.    PUBLICP is non-zero if this table should be given external visibility.  */
  2089. tree
  2090. finish_table (name, type, init, publicp)
  2091.      tree name, type, init;
  2092.      int publicp;
  2093. {
  2094.   tree itype, atype, decl;
  2095.   static tree empty_table;
  2096.   int is_empty = 0;
  2097.   tree asmspec;
  2098.  
  2099.   itype = build_index_type (size_int (list_length (init) - 1));
  2100.   atype = build_cplus_array_type (type, itype);
  2101.   layout_type (atype);
  2102.  
  2103.   if (TREE_VALUE (init) == integer_zero_node
  2104.       && TREE_CHAIN (init) == NULL_TREE)
  2105.     {
  2106.       if (empty_table == NULL_TREE)
  2107.     {
  2108.       empty_table = get_temp_name (atype, 1);
  2109.       init = build (CONSTRUCTOR, atype, NULL_TREE, init);
  2110.       TREE_CONSTANT (init) = 1;
  2111.       TREE_STATIC (init) = 1;
  2112.       DECL_INITIAL (empty_table) = init;
  2113.       asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
  2114.                   IDENTIFIER_POINTER (DECL_NAME (empty_table)));
  2115.       finish_decl (empty_table, init, asmspec, 0);
  2116.     }
  2117.       is_empty = 1;
  2118.     }
  2119.  
  2120.   if (name == NULL_TREE)
  2121.     {
  2122.       if (is_empty)
  2123.     return empty_table;
  2124.       decl = get_temp_name (atype, 1);
  2125.     }
  2126.   else
  2127.     {
  2128.       decl = build_decl (VAR_DECL, name, atype);
  2129.       decl = pushdecl (decl);
  2130.       TREE_STATIC (decl) = 1;
  2131.     }
  2132.  
  2133.   if (is_empty == 0)
  2134.     {
  2135.       TREE_PUBLIC (decl) = publicp;
  2136.       init = build (CONSTRUCTOR, atype, NULL_TREE, init);
  2137.       TREE_CONSTANT (init) = 1;
  2138.       TREE_STATIC (init) = 1;
  2139.       DECL_INITIAL (decl) = init;
  2140.       asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)),
  2141.                   IDENTIFIER_POINTER (DECL_NAME (decl)));
  2142.     }
  2143.   else
  2144.     {
  2145.       /* This will cause DECL to point to EMPTY_TABLE in rtl-land.  */
  2146.       DECL_EXTERNAL (decl) = 1;
  2147.       TREE_STATIC (decl) = 0;
  2148.       init = 0;
  2149.       asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
  2150.                   IDENTIFIER_POINTER (DECL_NAME (empty_table)));
  2151.     }
  2152.  
  2153.   finish_decl (decl, init, asmspec, 0);
  2154.   return decl;
  2155. }
  2156.  
  2157. /* Finish processing a builtin type TYPE.  It's name is NAME,
  2158.    its fields are in the array FIELDS.  LEN is the number of elements
  2159.    in FIELDS minus one, or put another way, it is the maximum subscript
  2160.    used in FIELDS.
  2161.  
  2162.    It is given the same alignment as ALIGN_TYPE.  */
  2163. void
  2164. finish_builtin_type (type, name, fields, len, align_type)
  2165.      tree type;
  2166.      char *name;
  2167.      tree fields[];
  2168.      int len;
  2169.      tree align_type;
  2170. {
  2171.   register int i;
  2172.  
  2173.   TYPE_FIELDS (type) = fields[0];
  2174.   for (i = 0; i < len; i++)
  2175.     {
  2176.       layout_type (TREE_TYPE (fields[i]));
  2177.       DECL_FIELD_CONTEXT (fields[i]) = type;
  2178.       TREE_CHAIN (fields[i]) = fields[i+1];
  2179.     }
  2180.   DECL_FIELD_CONTEXT (fields[i]) = type;
  2181.   DECL_CLASS_CONTEXT (fields[i]) = type;
  2182.   TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
  2183.   layout_type (type);
  2184. #if 0 /* not yet, should get fixed properly later */
  2185.   TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
  2186. #else
  2187.   TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
  2188. #endif
  2189.   layout_decl (TYPE_NAME (type), 0);
  2190. }
  2191.  
  2192. /* Auxiliary functions to make type signatures for
  2193.    `operator new' and `operator delete' correspond to
  2194.    what compiler will be expecting.  */
  2195.  
  2196. extern tree sizetype;
  2197.  
  2198. tree
  2199. coerce_new_type (type)
  2200.      tree type;
  2201. {
  2202.   int e1 = 0, e2 = 0;
  2203.  
  2204.   if (TREE_CODE (type) == METHOD_TYPE)
  2205.     type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
  2206.   if (TREE_TYPE (type) != ptr_type_node)
  2207.     e1 = 1, error ("`operator new' must return type `void *'");
  2208.  
  2209.   /* Technically the type must be `size_t', but we may not know
  2210.      what that is.  */
  2211.   if (TYPE_ARG_TYPES (type) == NULL_TREE)
  2212.     e1 = 1, error ("`operator new' takes type `size_t' parameter");
  2213.   else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
  2214.        || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
  2215.     e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
  2216.   if (e2)
  2217.     type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
  2218.   else if (e1)
  2219.     type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
  2220.   return type;
  2221. }
  2222.  
  2223. tree
  2224. coerce_delete_type (type)
  2225.      tree type;
  2226. {
  2227.   int e1 = 0, e2 = 0, e3 = 0;
  2228.   tree arg_types = TYPE_ARG_TYPES (type);
  2229.  
  2230.   if (TREE_CODE (type) == METHOD_TYPE)
  2231.     {
  2232.       type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
  2233.       arg_types = TREE_CHAIN (arg_types);
  2234.     }
  2235.   if (TREE_TYPE (type) != void_type_node)
  2236.     e1 = 1, error ("`operator delete' must return type `void'");
  2237.   if (arg_types == NULL_TREE
  2238.       || TREE_VALUE (arg_types) != ptr_type_node)
  2239.     e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
  2240.  
  2241.   if (arg_types
  2242.       && TREE_CHAIN (arg_types)
  2243.       && TREE_CHAIN (arg_types) != void_list_node)
  2244.     {
  2245.       /* Again, technically this argument must be `size_t', but again
  2246.      we may not know what that is.  */
  2247.       tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
  2248.       if (TREE_CODE (t2) != INTEGER_TYPE
  2249.       || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
  2250.     e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
  2251.       else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
  2252.     {
  2253.       e3 = 1;
  2254.       if (TREE_CHAIN (TREE_CHAIN (arg_types)))
  2255.         error ("too many arguments in declaration of `operator delete'");
  2256.       else
  2257.         error ("`...' invalid in specification of `operator delete'");
  2258.     }
  2259.     }
  2260.   if (e3)
  2261.     arg_types = tree_cons (NULL_TREE, ptr_type_node, build_tree_list (NULL_TREE, sizetype));
  2262.   else if (e3 |= e2)
  2263.     {
  2264.       if (arg_types == NULL_TREE)
  2265.     arg_types = void_list_node;
  2266.       else
  2267.     arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
  2268.     }
  2269.   else e3 |= e1;
  2270.  
  2271.   if (e3)
  2272.     type = build_function_type (void_type_node, arg_types);
  2273.  
  2274.   return type;
  2275. }
  2276.  
  2277. static void
  2278. write_vtable_entries (decl)
  2279.      tree decl;
  2280. {
  2281.   tree entries = TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)));
  2282.  
  2283.   if (flag_dossier)
  2284.     entries = TREE_CHAIN (entries);
  2285.  
  2286.   for (; entries; entries = TREE_CHAIN (entries))
  2287.     {
  2288.       tree fnaddr = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries));
  2289.       tree fn = TREE_OPERAND (fnaddr, 0);
  2290.       if (! DECL_EXTERNAL (fn) && ! TREE_ASM_WRITTEN (fn)
  2291.       && DECL_SAVED_INSNS (fn))
  2292.     {
  2293.       if (TREE_PUBLIC (DECL_CLASS_CONTEXT (fn)))
  2294.         TREE_PUBLIC (fn) = 1;
  2295.       TREE_ADDRESSABLE (fn) = 1;
  2296.       temporary_allocation ();
  2297.       output_inline_function (fn);
  2298.       permanent_allocation ();
  2299.     }
  2300.       else
  2301.     assemble_external (fn);
  2302.     }
  2303. }
  2304.  
  2305. /* Note even though prev is never used in here, walk_vtables
  2306.    expects this to have two arguments, so concede.  */
  2307. static void
  2308. finish_vtable_typedecl (prev, vars)
  2309.      tree prev, vars;
  2310. {
  2311.   tree decl = TYPE_BINFO_VTABLE (TREE_TYPE (vars));
  2312.  
  2313.   /* If we are controlled by `+e2', obey.  */
  2314.   if (write_virtuals == 2)
  2315.     {
  2316.       tree binfo = value_member (DECL_NAME (vars), pending_vtables);
  2317.       if (binfo)
  2318.     TREE_PURPOSE (binfo) = void_type_node;
  2319.       else
  2320.     decl = NULL_TREE;
  2321.     }
  2322.   /* If this type has inline virtual functions, then
  2323.      write those functions out now.  */
  2324.   if (decl && write_virtuals >= 0
  2325.       && ! DECL_EXTERNAL (decl) && (TREE_PUBLIC (decl) || TREE_USED (decl)))
  2326.     write_vtable_entries (decl);
  2327. }
  2328.  
  2329. static void
  2330. finish_vtable_vardecl (prev, vars)
  2331.      tree prev, vars;
  2332. {
  2333.   if (write_virtuals >= 0
  2334.       && ! DECL_EXTERNAL (vars) && (TREE_PUBLIC (vars) || TREE_USED (vars)))
  2335.     {
  2336.       extern tree the_null_vtable_entry;
  2337.  
  2338.       /* Stuff this virtual function table's size into
  2339.      `pfn' slot of `the_null_vtable_entry'.  */
  2340.       tree nelts = array_type_nelts (TREE_TYPE (vars));
  2341.       SET_FNADDR_FROM_VTABLE_ENTRY (the_null_vtable_entry, nelts);
  2342.       /* Kick out the dossier before writing out the vtable.  */
  2343.       if (flag_dossier)
  2344.     rest_of_decl_compilation (TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (vars))))), 0), 0, 1, 1);
  2345.  
  2346.       /* Write it out.  */
  2347.       write_vtable_entries (vars);
  2348.       if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
  2349.     store_init_value (vars, DECL_INITIAL (vars));
  2350.  
  2351. #ifdef DWARF_DEBUGGING_INFO
  2352.       if (write_symbols == DWARF_DEBUG)
  2353.     {
  2354.       /* Mark the VAR_DECL node representing the vtable itself as a
  2355.          "gratuitous" one, thereby forcing dwarfout.c to ignore it.
  2356.          It is rather important that such things be ignored because
  2357.          any effort to actually generate DWARF for them will run
  2358.          into trouble when/if we encounter code like:
  2359.  
  2360.         #pragma interface
  2361.         struct S { virtual void member (); };
  2362.  
  2363.           because the artificial declaration of the vtable itself (as
  2364.           manufactured by the g++ front end) will say that the vtable
  2365.           is a static member of `S' but only *after* the debug output
  2366.           for the definition of `S' has already been output.  This causes
  2367.           grief because the DWARF entry for the definition of the vtable
  2368.           will try to refer back to an earlier *declaration* of the
  2369.           vtable as a static member of `S' and there won't be one.
  2370.           We might be able to arrange to have the "vtable static member"
  2371.           attached to the member list for `S' before the debug info for
  2372.           `S' get written (which would solve the problem) but that would
  2373.           require more intrusive changes to the g++ front end.  */
  2374.  
  2375.       DECL_IGNORED_P (vars) = 1;
  2376.     }
  2377. #endif /* DWARF_DEBUGGING_INFO */
  2378.  
  2379.       rest_of_decl_compilation (vars, 0, 1, 1);
  2380.     }
  2381.   /* We know that PREV must be non-zero here.  */
  2382.   TREE_CHAIN (prev) = TREE_CHAIN (vars);
  2383. }
  2384.  
  2385. void
  2386. walk_vtables (typedecl_fn, vardecl_fn)
  2387.      register void (*typedecl_fn)();
  2388.      register void (*vardecl_fn)();
  2389. {
  2390.   tree prev, vars;
  2391.  
  2392.   for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
  2393.     {
  2394.       register tree type = TREE_TYPE (vars);
  2395.  
  2396.       if (TREE_CODE (vars) == TYPE_DECL
  2397.       && type != error_mark_node
  2398.       && TYPE_LANG_SPECIFIC (type)
  2399.       && CLASSTYPE_VSIZE (type))
  2400.     {
  2401.       if (typedecl_fn) (*typedecl_fn) (prev, vars);
  2402.     }
  2403.       else if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
  2404.     {
  2405.       if (vardecl_fn) (*vardecl_fn) (prev, vars);
  2406.     }
  2407.       else
  2408.     prev = vars;
  2409.     }
  2410. }
  2411.  
  2412. extern int parse_time, varconst_time;
  2413.  
  2414. #define TIMEVAR(VAR, BODY)    \
  2415. do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
  2416.  
  2417. /* This routine is called from the last rule in yyparse ().
  2418.    Its job is to create all the code needed to initialize and
  2419.    destroy the global aggregates.  We do the destruction
  2420.    first, since that way we only need to reverse the decls once.  */
  2421.  
  2422. void
  2423. finish_file ()
  2424. {
  2425.   extern int lineno;
  2426.   int start_time, this_time;
  2427.  
  2428.   tree fnname;
  2429.   tree vars = static_aggregates;
  2430.   int needs_cleaning = 0, needs_messing_up = 0;
  2431.  
  2432.   if (flag_detailed_statistics)
  2433.     dump_tree_statistics ();
  2434.  
  2435.   /* Bad parse errors.  Just forget about it.  */
  2436.   if (! global_bindings_p () || current_class_type)
  2437.     return;
  2438.  
  2439.   start_time = get_run_time ();
  2440.  
  2441.   /* Push into C language context, because that's all
  2442.      we'll need here.  */
  2443.   push_lang_context (lang_name_c);
  2444.  
  2445.   /* Set up the name of the file-level functions we may need.  */
  2446.   /* Use a global object (which is already required to be unique over
  2447.      the program) rather than the file name (which imposes extra
  2448.      constraints).  -- Raeburn@MIT.EDU, 10 Jan 1990.  */
  2449.  
  2450.   /* See if we really need the hassle.  */
  2451.   while (vars && needs_cleaning == 0)
  2452.     {
  2453.       tree decl = TREE_VALUE (vars);
  2454.       tree type = TREE_TYPE (decl);
  2455.       if (TYPE_NEEDS_DESTRUCTOR (type))
  2456.     {
  2457.       needs_cleaning = 1;
  2458.       needs_messing_up = 1;
  2459.       break;
  2460.     }
  2461.       else
  2462.     needs_messing_up |= TYPE_NEEDS_CONSTRUCTING (type);
  2463.       vars = TREE_CHAIN (vars);
  2464.     }
  2465.   if (needs_cleaning == 0)
  2466.     goto mess_up;
  2467.  
  2468.   /* Otherwise, GDB can get confused, because in only knows
  2469.      about source for LINENO-1 lines.  */
  2470.   lineno -= 1;
  2471.  
  2472.   fnname = get_file_function_name ('D');
  2473.   start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
  2474.   fnname = DECL_ASSEMBLER_NAME (current_function_decl);
  2475.   store_parm_decls ();
  2476.  
  2477.   pushlevel (0);
  2478.   clear_last_expr ();
  2479.   push_momentary ();
  2480.   expand_start_bindings (0);
  2481.  
  2482.   /* These must be done in backward order to destroy,
  2483.      in which they happen to be!  */
  2484.   while (vars)
  2485.     {
  2486.       tree decl = TREE_VALUE (vars);
  2487.       tree type = TREE_TYPE (decl);
  2488.       tree temp = TREE_PURPOSE (vars);
  2489.  
  2490.       if (TYPE_NEEDS_DESTRUCTOR (type))
  2491.     {
  2492.       if (TREE_STATIC (vars))
  2493.         expand_start_cond (build_binary_op (NE_EXPR, temp, integer_zero_node, 1), 0);
  2494.       if (TREE_CODE (type) == ARRAY_TYPE)
  2495.         temp = decl;
  2496.       else
  2497.         {
  2498.           mark_addressable (decl);
  2499.           temp = build1 (ADDR_EXPR, TYPE_POINTER_TO (type), decl);
  2500.         }
  2501.       temp = build_delete (TREE_TYPE (temp), temp,
  2502.                    integer_two_node, LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
  2503.       expand_expr_stmt (temp);
  2504.  
  2505.       if (TREE_STATIC (vars))
  2506.         expand_end_cond ();
  2507.     }
  2508.       vars = TREE_CHAIN (vars);
  2509.     }
  2510.  
  2511.   expand_end_bindings (getdecls(), 1, 0);
  2512.   poplevel (1, 0, 0);
  2513.   pop_momentary ();
  2514.  
  2515.   finish_function (lineno, 0);
  2516.  
  2517.   assemble_destructor (IDENTIFIER_POINTER (fnname));
  2518.  
  2519.   /* if it needed cleaning, then it will need messing up: drop through  */
  2520.  
  2521.  mess_up:
  2522.   /* Must do this while we think we are at the top level.  */
  2523.   vars = nreverse (static_aggregates);
  2524.   if (vars != NULL_TREE)
  2525.     {
  2526.       fnname = get_file_function_name ('I');
  2527.       start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
  2528.       fnname = DECL_ASSEMBLER_NAME (current_function_decl);
  2529.       store_parm_decls ();
  2530.  
  2531.       pushlevel (0);
  2532.       clear_last_expr ();
  2533.       push_momentary ();
  2534.       expand_start_bindings (0);
  2535.  
  2536.       while (vars)
  2537.     {
  2538.       tree decl = TREE_VALUE (vars);
  2539.       tree init = TREE_PURPOSE (vars);
  2540.  
  2541.       /* If this was a static attribute within some function's scope,
  2542.          then don't initialize it here.  Also, don't bother
  2543.          with initializers that contain errors.  */
  2544.       if (TREE_STATIC (vars)
  2545.           || (init && TREE_CODE (init) == TREE_LIST
  2546.           && value_member (error_mark_node, init)))
  2547.         {
  2548.           vars = TREE_CHAIN (vars);
  2549.           continue;
  2550.         }
  2551.  
  2552.       if (TREE_CODE (decl) == VAR_DECL)
  2553.         {
  2554.           /* Set these global variables so that GDB at least puts
  2555.          us near the declaration which required the initialization.  */
  2556.           input_filename = DECL_SOURCE_FILE (decl);
  2557.           lineno = DECL_SOURCE_LINE (decl);
  2558.           emit_note (input_filename, lineno);
  2559.  
  2560.           if (init)
  2561.         {
  2562.           if (TREE_CODE (init) == VAR_DECL)
  2563.             {
  2564.               /* This behavior results when there are
  2565.              multiple declarations of an aggregate,
  2566.              the last of which defines it.  */
  2567.               if (DECL_RTL (init) == DECL_RTL (decl))
  2568.             {
  2569.               my_friendly_assert (DECL_INITIAL (decl) == error_mark_node
  2570.                   || (TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
  2571.                       && CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) == NULL_TREE),
  2572.                           199);
  2573.               init = DECL_INITIAL (init);
  2574.               if (TREE_CODE (init) == CONSTRUCTOR
  2575.                   && CONSTRUCTOR_ELTS (init) == NULL_TREE)
  2576.                 init = NULL_TREE;
  2577.             }
  2578. #if 0
  2579.               else if (TREE_TYPE (decl) == TREE_TYPE (init))
  2580.             {
  2581. #if 1
  2582.               my_friendly_abort (200);
  2583. #else
  2584.               /* point to real decl's rtl anyway.  */
  2585.               DECL_RTL (init) = DECL_RTL (decl);
  2586.               my_friendly_assert (DECL_INITIAL (decl) == error_mark_node,
  2587.                           201);
  2588.               init = DECL_INITIAL (init);
  2589. #endif                /* 1 */
  2590.             }
  2591. #endif                /* 0 */
  2592.             }
  2593.         }
  2594.           if (IS_AGGR_TYPE (TREE_TYPE (decl))
  2595.           || init == 0
  2596.           || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
  2597.         {
  2598.           /* Set this up so is_friend() works properly on _GLOBAL_ fns.  */
  2599.           tree old_dcc = DECL_CLASS_CONTEXT (current_function_decl);
  2600.           if (old_dcc == NULL_TREE)
  2601.             DECL_CLASS_CONTEXT (current_function_decl) = TREE_TYPE (decl);
  2602.           expand_aggr_init (decl, init, 0);
  2603.           DECL_CLASS_CONTEXT (current_function_decl) = old_dcc;
  2604.         }
  2605.           else if (TREE_CODE (init) == TREE_VEC)
  2606.         {
  2607.           expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
  2608.                         TREE_VEC_ELT (init, 1),
  2609.                         TREE_VEC_ELT (init, 2), 0),
  2610.                    const0_rtx, VOIDmode, 0);
  2611.           free_temp_slots ();
  2612.         }
  2613.           else
  2614.         expand_assignment (decl, init, 0, 0);
  2615.         }
  2616.       else if (TREE_CODE (decl) == SAVE_EXPR)
  2617.         {
  2618.           if (! PARM_DECL_EXPR (decl))
  2619.         {
  2620.           /* a `new' expression at top level.  */
  2621.           expand_expr (decl, const0_rtx, VOIDmode, 0);
  2622.           free_temp_slots ();
  2623.           expand_aggr_init (build_indirect_ref (decl, NULL_PTR), init, 0);
  2624.         }
  2625.         }
  2626.       else if (decl == error_mark_node)
  2627.         ;
  2628.       else my_friendly_abort (22);
  2629.       vars = TREE_CHAIN (vars);
  2630.     }
  2631.  
  2632.       expand_end_bindings (getdecls(), 1, 0);
  2633.       poplevel (1, 0, 0);
  2634.       pop_momentary ();
  2635.  
  2636.       finish_function (lineno, 0);
  2637.       assemble_constructor (IDENTIFIER_POINTER (fnname));
  2638.     }
  2639.  
  2640.   /* Done with C language context needs.  */
  2641.   pop_lang_context ();
  2642.  
  2643.   /* Now write out any static class variables (which may have since
  2644.      learned how to be initialized).  */
  2645.   while (pending_statics)
  2646.     {
  2647.       tree decl = TREE_VALUE (pending_statics);
  2648.       if (TREE_USED (decl) == 1
  2649.       || TREE_READONLY (decl) == 0
  2650.       || DECL_INITIAL (decl) == 0)
  2651.     rest_of_decl_compilation (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
  2652.       pending_statics = TREE_CHAIN (pending_statics);
  2653.     }
  2654.  
  2655.   this_time = get_run_time ();
  2656.   parse_time -= this_time - start_time;
  2657.   varconst_time += this_time - start_time;
  2658.  
  2659.   /* Now write out inline functions which had their addresses taken
  2660.      and which were not declared virtual and which were not declared
  2661.      `extern inline'.  */
  2662.   while (pending_addressable_inlines)
  2663.     {
  2664.       tree decl = TREE_VALUE (pending_addressable_inlines);
  2665.       if (! TREE_ASM_WRITTEN (decl)
  2666.       && ! DECL_EXTERNAL (decl)
  2667.       && DECL_SAVED_INSNS (decl))
  2668.     {
  2669.       temporary_allocation ();
  2670.       output_inline_function (decl);
  2671.       permanent_allocation ();
  2672.     }
  2673.       pending_addressable_inlines = TREE_CHAIN (pending_addressable_inlines);
  2674.     }
  2675.  
  2676.   start_time = get_run_time ();
  2677.  
  2678.   /* Now delete from the chain of variables all virtual function tables.
  2679.      We output them all ourselves, because each will be treated specially.  */
  2680.  
  2681. #if 1
  2682.   /* The reason for pushing garbage onto the global_binding_level is to
  2683.      ensure that we can slice out _DECLs which pertain to virtual function
  2684.      tables.  If the last thing pushed onto the global_binding_level was a
  2685.      virtual function table, then slicing it out would slice away all the
  2686.      decls (i.e., we lose the head of the chain).
  2687.  
  2688.      There are several ways of getting the same effect, from changing the
  2689.      way that iterators over the chain treat the elements that pertain to
  2690.      virtual function tables, moving the implementation of this code to
  2691.      cp-decl.c (where we can manipulate global_binding_level directly),
  2692.      popping the garbage after pushing it and slicing away the vtable
  2693.      stuff, or just leaving it alone. */
  2694.  
  2695.   /* Make last thing in global scope not be a virtual function table.  */
  2696. #if 0 /* not yet, should get fixed properly later */
  2697.   vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
  2698. #else
  2699.   vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
  2700. #endif
  2701.   DECL_IGNORED_P (vars) = 1;
  2702.   DECL_SOURCE_LINE (vars) = 0;
  2703.   pushdecl (vars);
  2704. #endif
  2705.  
  2706.   walk_vtables (finish_vtable_typedecl, finish_vtable_vardecl);
  2707.  
  2708.   if (write_virtuals == 2)
  2709.     {
  2710.       /* Now complain about an virtual function tables promised
  2711.      but not delivered.  */
  2712.       while (pending_vtables)
  2713.     {
  2714.       if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
  2715.         error ("virtual function table for `%s' not defined",
  2716.            IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
  2717.       pending_vtables = TREE_CHAIN (pending_vtables);
  2718.     }
  2719.     }
  2720.  
  2721.   permanent_allocation ();
  2722.   this_time = get_run_time ();
  2723.   parse_time -= this_time - start_time;
  2724.   varconst_time += this_time - start_time;
  2725.  
  2726.   if (flag_detailed_statistics)
  2727.     dump_time_statistics ();
  2728. }
  2729.